JK_BullP_AutoTrader2

Author: Copyright � 2005, Johnny Kor
Orders Execution
Checks for the total of open ordersIt can change open orders parameters, due to possible stepping strategyIt automatically opens orders when conditions are reached
Indicators Used
Bulls Power indicator
1 Views
0 Downloads
0 Favorites
JK_BullP_AutoTrader2
//+------------------------------------------------------------------+
//|                                          JK_BullP_AutoTrader.mq4 |
//|                                     Copyright © 2005, Johnny Kor |
//|                                                   autojk@mail.ru |
//|        On-Line Testing http://vesna.on-plus.ru/forex/stat/69740/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Johnny Kor"
#property link      "autojk@mail.ru"
//---- input parameters
extern double TakeProfit = 500;
extern double Lots = 8.5;
extern double StopLoss = 20;
extern int TrailingStop = 10;
extern double Patr = 1, Prange = 1, Kstop = 0.1, kts = 2, Vts = 2; 
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
   double pos1pre, pos2cur, hzbul1, hzbul2, hzbear1, hzbear2;
   int cnt, ticket, total, TotalOpenOrders;
   pos1pre = iBullsPower(NULL, 0, 13, PRICE_CLOSE, 2);
   pos2cur = iBullsPower(NULL, 0, 13, PRICE_CLOSE, 1);
   total = OrdersTotal();
   int H, L;
   for(cnt = 0; cnt < 30; cnt++)
     {
       if(H == 0)
         {
           if(H < High[cnt]) 
               H = High[cnt];
         }
     }
   for(cnt = 0; cnt < 30; cnt++)
     {
       if(L == 0)
         {
           if(L > Low[cnt]) 
               L = Low[cnt];
         }
     }
   Comment("  BullsPower - ", pos1pre, "  BearsPower - ", pos2cur);
   int j;
   for(cnt = 0; cnt < total; cnt++)
     {
       OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
       if(OrderType() <= OP_SELL && // ýòî îòêðûòàÿ ïîçèöèÿ? OP_BUY èëè OP_SELL 
          OrderSymbol() == Symbol())    // èíñòðóìåíò ñîâïàäàåò?
         {
           j = 2;
           if(OrderType() == OP_BUY)   // îòêðûòà äëèííàÿ ïîçèöèÿ
             {
               // ïðîâåðèì - ìîæåò ìîæíî/íóæíî óæå òðåéëèíã ñòîï ñòàâèòü?
               if(TrailingStop > 0)  // ïîëüçîâàòåëü âûñòàâèë â íàñòðîéêàõ òðåéëèíãñòîï
                 {                 // çíà÷èò ìû èäåì åãî ïðîâåðÿòü
                   if(Bid- OrderOpenPrice() > Point*TrailingStop)
                     {
                       if(OrderStopLoss() < Bid - Point*TrailingStop)
                         {
                           OrderModify(OrderTicket(), OrderOpenPrice(), 
                                       Bid-Point*TrailingStop, 
                                       OrderTakeProfit(), 0, Red);
                           return(0);
                         }
                     }
                 }
             }
           else // èíà÷å ýòî êîðîòêàÿ ïîçèöèÿ
             {
               // ïðîâåðèì - ìîæåò ìîæíî/íóæíî óæå òðåéëèíã ñòîï ñòàâèòü?
               if(TrailingStop > 0)  // ïîëüçîâàòåëü âûñòàâèë â íàñòðîéêàõ òðåéëèíãñòîï
                 {                 // çíà÷èò ìû èäåì åãî ïðîâåðÿòü
                   if((OrderOpenPrice() - Ask) > (Point*TrailingStop))
                     {
                       if(OrderStopLoss() == 0.0 || 
                          OrderStopLoss() > (Ask + Point*TrailingStop))
                         {
                           OrderModify(OrderTicket(), OrderOpenPrice(), 
                                       Ask + Point*TrailingStop, 
                                       OrderTakeProfit(), 0, Red);
                           return(0);
                         }
                     }
                 }
             }
         }
     }
   if(pos1pre > pos2cur && pos2cur > 0  && j < 2)
     {
       OrderSend(Symbol(), OP_SELL, Lots, Bid, 3, Bid + StopLoss*Point, 
                 Bid - TakeProfit*Point, NULL, 0, 0, Red);
     }   
   if(pos2cur < 0 && j < 1)
     {
       OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, Ask - StopLoss*Point, 
                 Ask + TakeProfit*Point, NULL, 0, 0, Red);
     }
   return(0);
  }
//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---