Range Breakout strategy MQL4

 //+------------------------------------------------------------------+

//|                                      range breakout strategy.mq4 |

//|                                                    Pulkit Chadha |

//|                                                    +918126282062 |

//+------------------------------------------------------------------+

#property copyright "Pulkit Chadha"

#property link      "+918126282062"

#property version   "1.00"

#property strict


extern string TradeStartTime = "15:05";//StartTime

extern string TradeStopTime = "15:22";//EndTIME

bool EAActivated=false,BUY=FALSE,SHORT=FALSE;

double highestPrice  = 0;   // Initialize highest value to lowest possible value

double lowestPrice =  10000000000;  

 int i=0,j=0;  

//+------------------------------------------------------------------+

//| Expert initialization function                                   |

//+------------------------------------------------------------------+

int OnInit()

  {

//---

   

//---

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Expert deinitialization function                                 |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

  {

//---

   

  }

//+------------------------------------------------------------------+

//| Expert tick function                                             |

//+------------------------------------------------------------------+

datetime startTime ,stopTime;

void OnTick()

  {

   startTime = StrToTime(TradeStartTime);

 stopTime = StrToTime(TradeStopTime);

   


    if (TimeCurrent()>StrToTime(TradeStopTime))

    {

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

    {  

        if (Time[i] >= startTime && Time[i] <= stopTime)

        {if (High[i] > highestPrice)

                   { highestPrice = High[i];}

                   

                if (Low[i] < lowestPrice)

                   { lowestPrice = Low[i];}

        }

   }

    }

    

    

    Comment("Highest value: "+ highestPrice+"\nLowest= "+lowestPrice);

    

   

   

   if(Close[0]>highestPrice&&highestPrice>0&&BUY==FALSE&&TimeCurrent()>StrToTime(TradeStopTime))

   {

   BUY =TRUE;SHORT=FALSE;buydraw();

   Alert("BUY @ "+Symbol());SendNotification("BUY @ "+Symbol());

   

   }

   

   if(Close[0]<lowestPrice&&lowestPrice>0&&SHORT==FALSE&&TimeCurrent()>StrToTime(TradeStopTime))

   {

   BUY =FALSE;SHORT=TRUE;selldraw();

   Alert("SELL @ "+Symbol());SendNotification("SELL @ "+Symbol());

   

   }

   

   

   

   

   

  }

//+------------------------------------------------------------------+

 void selldraw()

           {  ObjectCreate("ShortSIGNAL"+i+ Time[0],OBJ_ARROW_DOWN,0,Time[0],High[0]);

            ObjectSet("ShortSIGNAL"+i+ Time[0],OBJPROP_WIDTH,3);

            ObjectSet("ShortSIGNAL"+i+ Time[0],OBJPROP_ARROWCODE,234);

            ObjectSet("ShortSIGNAL"+i+ Time[0],OBJPROP_COLOR,Red);

            ObjectSetInteger(0,"ShortSIGNAL"+i,OBJPROP_ANCHOR,ANCHOR_TOP);

            ObjectCreate(0, "abutton1"+i, OBJ_TEXT, 0,Time[0], High[1]);

            ObjectSetText( "abutton1"+i,"Short@"+Ask, 12, "Times New Roman", clrRed);

            ObjectSetInteger( "abutton1"+i, 0, Time[0], Close[0]);

            i++;

            }

            void buydraw()

           { 

               ObjectCreate("BUYSIGNAL"+j+ Time[0],OBJ_ARROW_UP,0,Time[0],Low[1]);

               ObjectSet("BUYSIGNAL"+j+ Time[0],OBJPROP_COLOR,Blue);

               ObjectSet("BUYSIGNAL"+j+ Time[0],OBJPROP_ARROWCODE,233);

               ObjectSet("BUYSIGNAL"+j+ Time[0],OBJPROP_WIDTH,3);

               ObjectSetInteger(0,"BUYSIGNAL"+j+ Time[0],OBJPROP_ANCHOR,ANCHOR_BOTTOM);

               ObjectCreate(0, "button"+j+ Time[0], OBJ_TEXT, 0,Time[0], Low[1]);

               ObjectSetText( "button"+j+ Time[0],"Buy@"+Ask,12 , "Times New Roman", clrRed);

               ObjectSetInteger("button"+j+ Time[0], 0, Time[0], Close[0]);

               j++;

           }

Comments

Popular posts from this blog

MQL5 : Add time to current time in mins

MQL5: Closed order detail