cm_ea_Stop_Orders_Candle

Price Data Components
Series array that contains open time of each bar
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
0 Views
0 Downloads
0 Favorites
cm_ea_Stop_Orders_Candle
ÿþ//+------------------------------------------------------------------+

#property copyright "Copyright © 2017, http://cmillion.ru"

#property link      "cmillion@narod.ru"

#property description "#AB0=02;820NBAO >@45@0 Buy stop 8 Sell stop =0 >48=0:>2> C:070==>5 :>;8G5AB2> ?C=:B>2 >B F5=K >B:@KB8O A25G8. 5;8G8=0 B59:0 8 AB>?0 C:07K205BAO 2 ?C=:B0E.  07<5@ ;>B0 B0: 65 C:07K205BAO 2@CG=CN 2 =0AB@>9:5 A>2K. @45@0 2KAB02;ONBAO B>;L:> =0 >B:@KB88 =>2>9 A25G8. > 55 70:@KB8N, 2A5 >B;>65==K5 >@45@0 C40;ONBAO."

#property description "!>25B=8: A>740= 4;O B5AB8@>20=8O, @01>B0 =0 @50;5 =5 70?@5I5=0, => ?@8 ?5@5703@C7:5 B5@<8=0;0 ?@>87>945B ?5@5CAB0=>2:0 >@45@>2.";

//--------------------------------------------------------------------*/

input ENUM_TIMEFRAMES timeframe     = 0;           //5@8>4 A25G59

input int      DeltaStop            = 20;          //@0AAB>O=85 4> AB>? >@45@0

extern int     Stoploss             = 20,          //AB>?;>AA 48A:@5B=> A25G59

               Takeprofit           = 10;          //B59:?@>D8B

extern double  Lot                  = 0.10;        //;>B

input int      Slippage             = 3;           //?@>A:0;L7K20=85

extern int     Magic                = 1;

//--------------------------------------------------------------------

int TimeBar,STOPLEVEL;

string val;

//-------------------------------------------------------------------- 

int OnInit()

{ 

   val = " "+AccountCurrency();

   return(INIT_SUCCEEDED);

}

//-------------------------------------------------------------------

void OnTick()

{

   if (!IsTradeAllowed()) return;

   STOPLEVEL=MarketInfo(Symbol(),MODE_STOPLEVEL);

   double OSL,OTP,OOP,SL,TP;

   int b=0,s=0,tip,bs=0,ss=0;

   for (int i=0; i<OrdersTotal(); i++)

   {    

      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

      { 

         if (OrderSymbol()==Symbol() && Magic==OrderMagicNumber())

         { 

            tip = OrderType(); 

            OSL = NormalizeDouble(OrderStopLoss(),Digits);

            OTP = NormalizeDouble(OrderTakeProfit(),Digits);

            OOP = NormalizeDouble(OrderOpenPrice(),Digits);

            SL=OSL;TP=OTP;

            if (tip==OP_BUY)             

            {  

               b++; 

               if (OSL==0 && Stoploss>=STOPLEVEL && Stoploss!=0)

               {

                  SL = NormalizeDouble(OOP - Stoploss   * Point,Digits);

               } 

               if (OTP==0 && Takeprofit>=STOPLEVEL && Takeprofit!=0)

               {

                  TP = NormalizeDouble(OOP + Takeprofit * Point,Digits);

               } 

               if (SL != OSL || TP != OTP)

               {  

                  if (!OrderModify(OrderTicket(),OOP,SL,TP,0,White)) Print("Error OrderModify <<",(GetLastError()),">> ");

               }

            }                                         

            if (tip==OP_SELL)        

            {

               s++;

               if (OSL==0 && Stoploss>=STOPLEVEL && Stoploss!=0)

               {

                  SL = NormalizeDouble(OOP + Stoploss   * Point,Digits);

               }

               if (OTP==0 && Takeprofit>=STOPLEVEL && Takeprofit!=0)

               {

                  TP = NormalizeDouble(OOP - Takeprofit * Point,Digits);

               }

               if (SL != OSL || TP != OTP)

               {  

                  if (!OrderModify(OrderTicket(),OOP,SL,TP,0,White)) Print("Error OrderModify <<",(GetLastError()),">> ");

               }

            } 

            if (tip==OP_SELLSTOP) ss=OrderTicket();

            if (tip==OP_BUYSTOP) bs=OrderTicket();

         }

      }

   } 



   //----------------------------------------------------------------

   if (bs==0)

   {

      if (OrderSend(Symbol(),OP_BUYSTOP,Lot,NormalizeDouble(Ask+DeltaStop*Point,Digits),Slippage,0,0,NULL,Magic,0)!=-1) TimeBar=iTime(NULL,timeframe,0); 

      else Print("H81:0 >B:@KB8O >@45@0 <<",(GetLastError()),">>  ");

   }

   if (ss==0)

   {

      if (OrderSend(Symbol(),OP_SELLSTOP,Lot,NormalizeDouble(Bid-DeltaStop*Point,Digits),Slippage,0,0,NULL,Magic,0)!=-1) TimeBar=iTime(NULL,timeframe,0); 

      else Print("H81:0 >B:@KB8O >@45@0 <<",(GetLastError()),">>  ");

   }

   if (TimeBar==iTime(NULL,timeframe,0)) return;

   int err;

   if (bs>0) err=OrderDelete(bs);

   if (ss>0) err=OrderDelete(ss);



}

//--------------------------------------------------------------------

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 ---