Please fix this indicator or EA - page 195

 
rojack2:
Hi everyone can someone please make this indicator alert me on a current candle not after its closed. i wont mind if the arrow appears and disappears. please

Post your request in the Freelance section.

 

helo.. i need convert this mq4 indicator to mq5..please help me..


***

Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • 2021.01.16
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
 
manakkalpitha manakkalpitha :

helo.. i need convert this mq4 indicator to mq5..please help me..


***

To insert the code, use the buttons:  Code and  Attach file.

 

helo.. i need convert this mq4 indicator to mq5..please help me..


//+------------------------------------------------------------------+
//|                                           PreviousCandleHiLo.mq4 |
//|                                                            hairi |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "hairi"
#property link      "https://www.mql5.com/en/users/hairi"
#property version   "1.00"
#property description   "Previous Candle Hi-Lo"
#property strict
#property indicator_chart_window

//+------------------------------------------------------------------+
//| Input variable                                                   |
//+------------------------------------------------------------------+
input ENUM_LINE_STYLE   linestyle   = STYLE_DOT;         // Line Style
input color             H1_color    = clrRed,            // Prev H1 color
                        H4_color    = clrGreen,          // Prev H4 color
                        D1_color    = clrBlue,           // Prev Day color
                        W1_color    = clrGold;           // Prev Week color

int         CalcDay = 7;
int         CalcBar = 0;
string      Objname,
ObjIdentifier="IN_";

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
   return(INIT_SUCCEEDED);
}   
//+------------------------------------------------------------------+
//| Deinit                                                           |
//+------------------------------------------------------------------+
int deinit()
  {
   ObjectDeleteAll();
   return (0);
  }

//+------------------------------------------------------------------+
//| Indicator Start                                                  |
//+------------------------------------------------------------------+
int start()
  {
   int BarCheck=IndicatorCounted();
   if(BarCheck < 0) return (-1);
   if(BarCheck>0) BarCheck--;
   int TotalBar=Bars-BarCheck;

   for(int BarMeasure=0; BarMeasure<=240; BarMeasure++)
     {
      double H1_High = 0, H1_Low = 0, H1_Open = 0, H1_Close = 0;
      double H4_High = 0, H4_Low = 0, H4_Open = 0, H4_Close = 0;
      double D1_High = 0, D1_Low = 0, D1_Open = 0, D1_Close = 0;
      double W1_High = 0, W1_Low = 0, W1_Open = 0, W1_Close = 0;

      PrevPeriod(PERIOD_H1,H1_Low,H1_High,H1_Open,H1_Close,"Prev H1 High","Prev H1 Low","Prev H1 Close","Prev H1 Open",linestyle,H1_color,1);
      PrevPeriod(PERIOD_H4,H4_Low,H4_High,H4_Open,H4_Close,"Prev H4 High","Prev H4 Low","Prev H4 Close","Prev H4 Open",linestyle,H4_color,1);
      PrevPeriod(PERIOD_D1,D1_Low,D1_High,D1_Open,D1_Close,"Prev Day High","Prev Day Low","Prev Day Close","Prev Day Open",linestyle,D1_color,1);
      PrevPeriod(PERIOD_W1,W1_Low,W1_High,W1_Open,W1_Close,"Prev Week High","Prev Week Low","Prev Week Close","Prev Week Open",linestyle,W1_color,1);
     }
   return (0);
  }

//+------------------------------------------------------------------+
//| Object Delete all function                                       |
//+------------------------------------------------------------------+
void ObjectDeleteAll()
  {
   Comment("");
   ObjectsDeleteAll(0,ObjIdentifier);
  }
  
//+------------------------------------------------------------------+
//| Draw line function                                               |
//+------------------------------------------------------------------+
void DrawShortHLine(string nameX,int time1,double P0,int style,color clr,int width)
  {
   string objName;

   datetime T0 = iTime(Symbol(),PERIOD_H1,time1);
   datetime T1 = iTime(Symbol(),PERIOD_M1,1);

   objName=nameX;
   if(ObjectFind(0,ObjIdentifier+objName)!=0)
      ObjectCreate(ObjIdentifier+objName,OBJ_TREND,0,T0,P0,T1,P0);
   else
     {
      ObjectDelete(ObjIdentifier+objName);
      ObjectCreate(ObjIdentifier+objName,OBJ_TREND,0,T0,P0,T1,P0);
     }
   ObjectSetInteger(0,ObjIdentifier+objName,OBJPROP_STYLE,style);
   ObjectSetInteger(0,ObjIdentifier+objName,OBJPROP_COLOR,clr);
   ObjectSetInteger(0,ObjIdentifier+objName,OBJPROP_WIDTH,width);
   ObjectSetInteger(0,ObjIdentifier+objName,OBJPROP_RAY,false);
   ObjectSetInteger(0,ObjIdentifier+objName,OBJPROP_BACK,true);
//ObjectSetString (0,name,name);
  }

//+------------------------------------------------------------------+
//| Draw complete line function                                      |
//+------------------------------------------------------------------+
void HLine(string name,string desc,int pShiftTime,double pPrice,int pStyle,color pColor,int pWidth) export
  {
   DrawShortHLine(name,pShiftTime,pPrice,pStyle,pColor,pWidth);
   CreatePriceLabel(name+" Label",desc,pPrice,pColor);
   CreatePriceFlag(name+" Price",pPrice,pColor);
  }

//+------------------------------------------------------------------+
//| scale the view                                                   |
//+------------------------------------------------------------------+
int ChartScaleGet() export
  {
   long result=-1;
   ChartGetInteger(0,CHART_SCALE,0,result);
   return((int)result);
  }

//+------------------------------------------------------------------+
//| Create price flag function                                       |
//+------------------------------------------------------------------+
void CreatePriceFlag(string name,double price,color col) export
  {
   datetime time=Time[0]+Period()*60;

   if(ObjectFind(0,ObjIdentifier+name)!=0)
     {
      ObjectCreate(ObjIdentifier+name,OBJ_ARROW_RIGHT_PRICE,0,time,price);
      ObjectSetInteger(0,ObjIdentifier+name,OBJPROP_ANCHOR,ANCHOR_LEFT);
      ObjectSetInteger(0,ObjIdentifier+name,OBJPROP_COLOR,col);
     }

   else ObjectMove(ObjIdentifier+name,0,time,price);

  }

//+------------------------------------------------------------------+
//| Create price label function                                      |
//+------------------------------------------------------------------+
void CreatePriceLabel(string name,string desc,double price,color col) export
  {
   int Chart_Scale,Bar_Width;
   Chart_Scale=ChartScaleGet();

   if(Chart_Scale==0) Bar_Width=64;
   else if(Chart_Scale == 1) Bar_Width = 32;
   else if(Chart_Scale == 2) Bar_Width = 16;
   else if(Chart_Scale == 3) Bar_Width = 9;
   else if(Chart_Scale == 4) Bar_Width = 5;
   else if(Chart_Scale == 5) Bar_Width = 3;
   else Bar_Width=2;

   datetime time=Time[0]+Period()*60*Bar_Width;

   if(ObjectFind(0,ObjIdentifier+name)!=0)
     {
      ObjectCreate(ObjIdentifier+name,OBJ_TEXT,0,time,price);
      ObjectSetInteger(0,ObjIdentifier+name,OBJPROP_ANCHOR,ANCHOR_LEFT);
      ObjectSetString(0,ObjIdentifier+name,OBJPROP_TEXT,desc);
      ObjectSetString(0,ObjIdentifier+name,OBJPROP_FONT,"Arial");
      ObjectSetInteger(0,ObjIdentifier+name,OBJPROP_FONTSIZE,8);
      ObjectSetInteger(0,ObjIdentifier+name,OBJPROP_COLOR,col);
     }

   else ObjectMove(ObjIdentifier+name,0,time,price);
  }

//+------------------------------------------------------------------+
//| Previous period function                                         |
//+------------------------------------------------------------------+
void PrevPeriod(int period,double high,double low,double close,double open,string hiname,string lowname,string closename,string openname,int style,color col,int width)
  {
   PrevCandle(period,low,high,close,open);
   HLine(hiname,hiname,10,high,style,col,width);
   HLine(lowname,lowname,10,low,style,col,width);
   HLine(openname,openname,10,open,style,col,width);
   HLine(closename,closename,10,close,style,col,width);
  }

//+------------------------------------------------------------------+
//| Previous candle function                                         |
//+------------------------------------------------------------------+
void PrevCandle(int period,double &low,double &high,double &close,double &open)
  {
   low=iLow(_Symbol,period,1);
   high=iHigh(_Symbol,period,1);
   close=iClose(_Symbol,period,1);
   open=iOpen(_Symbol,period,1);
  }
//+------------------------------------------------------------------+
Files:
 

Hi Any one can help me to change lot size and add max profit function and brake even in my ea.

The code is below .

//---- input parameters

extern double experts = 1;

extern double beginPrice = 1.8014;

extern int    magicnumber = 777;

static int    prevtime = 0;

static double bl = 1000;

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

//| expert initialization function                                   |

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

int init()

  {

//----

   return(0);

  }

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

//| expert deinitialization function                                 |

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

int deinit()

  {

//----

   return(0);

  }

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

//| expert start function                                            |

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

int start()

  {

   if(Time[0] == prevtime) 

       return(0);

   prevtime = Time[0];

   if(!IsTradeAllowed()) 

     {

       prevtime = Time[1];

       return(0);

     }

//----

   int total = OrdersHistoryTotal();

   double money = bl * beginPrice;

   int i = 0;

   for (i = 0; i < total; i++) 

     {

       OrderSelect(i, SELECT_BY_POS, MODE_HISTORY);

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

         {

           if(OrderType() == OP_BUY) 

             {

               money = money + (OrderClosePrice() - 

                       OrderOpenPrice()) * 10 * OrderLots();

             } 

           else 

             {

               money = money - (OrderClosePrice() - 

                       OrderOpenPrice()) * 10 * OrderLots();

             }

         }

     }

   total = OrdersTotal();   

   double com =  bl;

   int tickbuy = -1;

   double buyprofit = 0;

   double buyvolume = 0;

   int ticksell = -1;

   double sellprofit = 0;

   double sellvolume = 0;

   for(i = 0; i < total; i++) 

     {

       OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

       if(OrderMagicNumber() == magicnumber) 

         {

           if(OrderType() == OP_BUY) 

             {

               if(OrderSymbol() == Symbol()) 

                 {

                   buyvolume = OrderLots();

                   money = money - 10 * buyvolume * OrderOpenPrice();

                   tickbuy = OrderTicket();

                   buyprofit = OrderProfit();

                 }

               com = com + 10 * OrderLots(); 

             } 

           else 

             {

               if(OrderSymbol() == Symbol()) 

                 {

                   sellvolume = OrderLots();

                   money = money + 10 * sellvolume * OrderOpenPrice();

                   ticksell = OrderTicket();

                   sellprofit = OrderProfit();

                 }

               com = com - 10 * OrderLots(); 

             }

         }

     }

   if(! IsTradeAllowed()) 

     {

       prevtime = Time[1];

       return(0);

     }

   closeby(ticksell, tickbuy);

   if(!IsTradeAllowed()) 

     {

       prevtime = Time[1];

       return(0);

     }

   double lots = 0;

   double price = 0;

   double dt = (money / Ask - com) * experts / (experts + 1);

   if(dt < 0) 

     {

       if(buyprofit < 0) 

           return(0);

       if(sellprofit > 0.01) 

           return(0);

       dt = (com - money / Bid) * experts / (experts + 1);

       if(dt < 1) 

         {

           closeby(tickbuy, ticksell);

           return(0);

         }

       if(dt > 10) 

           dt = 10;

       lots = MathFloor(dt) / 10;

       if(tickbuy >= 0) 

         {

           if(buyvolume > lots) 

             {

               OrderClose(tickbuy, lots, Bid, 3, Blue);

               Sleep(30000);

             } 

           else 

             {

               OrderClose(tickbuy, buyvolume, Bid, 3, Blue);

               tickbuy = -1;

               Sleep(30000);

             }

         } 

       else 

         {

           lots = getLots(lots);

           if(lots > 0) 

             {

               ticksell = OrderSend(Symbol(), OP_SELL, lots, Bid, 3, 

                          0, 0, "ArbitrageReverse", magicnumber, 0, Red);

               Sleep(30000);

             }

         }

     } 

   else 

     {

       if(sellprofit < 0) 

           return(0);

       if(buyprofit > 0.001) 

           return(0);

       if(dt < 1) 

         {

           closeby(ticksell, tickbuy);

           return(0);

         }

       if(dt > 10) 

           dt = 10;

       lots = MathFloor(dt) / 10;

       if(ticksell >= 0) 

         {

           if(sellvolume > lots) 

             {

               OrderClose(ticksell, lots, Ask, 3, Red);

               Sleep(30000);

             } 

           else 

             {

               OrderClose(ticksell, sellvolume, Ask, 3, Red);

               ticksell = -1;

               Sleep(30000);

             }

         } 

       else 

         {

           lots = getLots(lots);

           if(lots > 0) 

             {

               tickbuy = OrderSend(Symbol(), OP_BUY, lots, Ask, 3, 0, 

                         0, "ArbitrageReverse",  magicnumber, 0, Blue);

               Sleep(30000);

             }

         }

     }

//----

   if(!IsTradeAllowed()) 

     {

       prevtime = Time[1];

       return(0);

     }

   closeby(tickbuy, ticksell);

//----

   return(0);

  }

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

//|                                                                  |

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

void closeby(int sell, int buy) 

  {

   if(sell >= 0 && buy >= 0) 

     {

       OrderCloseBy(buy, sell, Green);

       Sleep(30000);

     }

  }

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

//|                                                                  |

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

double getLots(double lt) 

  {

   double marginrequired = MarketInfo(Symbol(), MODE_MARGINREQUIRED);

   double freemargin = AccountFreeMargin();

   if(freemargin > (marginrequired * lt)) 

     {

       return(lt);

     } 

   double result = freemargin / marginrequired;

   result = MathFloor(result * 10) / 10;

   return(result);

  }

//+------------------------------------------------------------------+
 
vishal122:

Hi Any one can help me to change lot size and add max profit function and brake even in my ea.

The code is below .

Do not double post!!

I have deleted your other topic.

 
Hi, I Code an EA with 7 Strategy’s. I would like to use them on Bitcoin. Well, the strategy’s are good, but need some little optimasiation, like little Chanches in the code and in the parameters. Now I want to ask, would anyone help me and join to my little Projekt ? 

Thanks for answering 
 

Hi, i have made a simple moving average arrow indicator and i want to use it as iCustom(...) in Expert Advisor. But EA doesn't work and i don't know how to fix it. when testing in strategy tester, no trade opens. and all arrow buffers are equal to zero!!. i have attached the source codes for indicator and EA.

indicator file: Fs 1MA

EA file: E11

i would be grateful if you help me.

Files:
Fs_1MA.mq5  5 kb
E11.mq5  10 kb
 
-3

I'm writing an (Expert Advisor) that opens a short positions once prices start to drops or once prices start to reverse in downtrend I want to catch the price at the exact reversal point. [enter image description here][1]

So far my code is opening short positions after price breaks the low of the previous 1 minute candle. How can I make it short once price start droping from it's on high. Here is the code I have wrote this far. How can I open short positions when price start to reverse

Timeline for MQL5 Metaquotes c++
Timeline for MQL5 Metaquotes c++
  • stackoverflow.com
Stack Overflow | The World’s Largest Online Community for Developers
Files:
sss.PNG  11 kb
 
Anyone this indicator fix to market watch and alerts?
Reason: