Coding help - page 477

 

Hello master coder,

I am try to write an PPO_alt indicator which is plot 1 in pictures a and b but it is not plot correctly in the realtime mode

so I try to modify the orignal PPO (plot 2) but it is still not correctly too. Please take a look and could you fix both of them.

Thanks in advance.

PS. Please ask more questions if it is not clear to you.

Files:
ppo_mod.rar  80 kb
 
download38:
Hello master coder,

I am try to write an PPO_alt indicator which is plot 1 in pictures a and b but it is not plot correctly in the realtime mode

so I try to modify the orignal PPO (plot 2) but it is still not correctly too. Please take a look and could you fix both of them.

Thanks in advance.

PS. Please ask more questions if it is not clear to you.

Why are you doing exactly the same thing in two loops?

 

Hello Mladen

need help

not getting live quote please help

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

//| expert initialization function |

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

#property indicator_chart_window

double ExtMapBuffer1[];

extern int RSI_periode = 14;

extern int RSI_level = 50;

extern color BuyColor = clrLime;

extern color SellColor = clrRed;

extern int horizontal = 20;

extern int vertical = 50;

extern int shift = 1;

extern double percent = 0.25;

extern string fontmode = "Arial";

extern int fontsize = 10;

extern color fontcolor = clrSkyBlue;

extern int columnspacing = 100;

int init()

{

//----

SetIndexStyle(0,DRAW_LINE);

SetIndexBuffer(0,ExtMapBuffer1);

//----

return(0);

}

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

//| expert deinitialization function |

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

int deinit()

{

//----

ObjectsDeleteAll();

ObjectDelete("INFO");

//----

return(0);

}

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

//| expert start function |

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

int start()

{

//----

string symlist2[] = {"NIFTY","B.NIFTY","XAUUSD", "GOLD"};

string symbol;

string info2[] = {MODE_HIGH,MODE_LOW,MODE_BID,MODE_ASK};

string infolabel;

string timeText[] = {"DayHigh","DayLow","Bid","Ask"};

string font = "Terminal";

int counted_bars=IndicatorCounted();

int symlimit = ArraySize(symlist2);

int timelimit = ArraySize(info2);

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

{

symbol = symlist2;

Display("symlabel" + symbol + i, horizontal,vertical);

ObjectSetText("symlabel" + symbol + i, "SYMBOL", fontsize, font, Pink);

Display("sym" + symbol + i, horizontal,vertical +((i+1)*18));

ObjectSetText("sym" + symbol + i, "" + symbol + "", fontsize, font, Yellow);

for(int j=0;j<timelimit;j++)

{

infolabel = info2[j];

Display("infolabel" + j, horizontal+((j+1)*100),vertical);

ObjectSetText("infolabel" + j, timeText[j], fontsize, font, Pink);

Display("infolabel2" + symbol + ((j+1)*columnspacing), horizontal+((j+1)*100),vertical +((i+1)*18));

ObjectSetText("infolabel2" +symbol+ ((j+1)*columnspacing), infolabel , fontsize, font, fontcolor);

}

}

//----

return(0);

}

void Display(string name, int x, int y)

{

ObjectCreate(name, OBJ_LABEL, 0, 0, 0);

ObjectSet(name, OBJPROP_CORNER, 0);

ObjectSet(name, OBJPROP_XDISTANCE, x);

ObjectSet(name, OBJPROP_YDISTANCE, y);

ObjectSet(name, OBJPROP_BACK, FALSE);

}

 
nbtrading:
Why are you doing exactly the same thing in two loops?

oh, I just want to plot a line with dots for easy to see it.

The important line is the multihigh which I have problem with.

Thanks for asking.

 

"Close BUY" and "Close SELL" algorithm

Hello Pro-Coders,

I am wondering if someone could review the "Close BUY" and "Close SELL" algorithm.

The EA is not opening new position after stop loss or trend change has taken place.

The system is just closing the position, next position will be opend on new trend change, which leads into loss of opportunity.

(Please see screenshot).

void CheckForClose()

{

RefreshRates();

double cl_diCustom0 = iCustom(s_symbol,TenkanKijunTf,"Tenkan Sen-Kijun Sen",0,Tenkan,Kijun,0,bar);

double cl_diCustom1 = iCustom(s_symbol,TenkanKijunTf,"Tenkan Sen-Kijun Sen",0,Tenkan,Kijun,1,bar);

double cl_diCustom2 = iCustom(s_symbol,TenkanKijunTf,"Tenkan Sen-Kijun Sen",0,Tenkan,Kijun,1,bar);

double cl_diCustom3 = iCustom(s_symbol,TenkanKijunTf,"Tenkan Sen-Kijun Sen",0,Tenkan,Kijun,1,bar+1);

double cl_diMA3 = iMA(s_symbol,MaTimeframe,MaPeriod,0,MaType,PRICE_CLOSE,bar);

double cl_diMA4 = iMA(s_symbol,MaTimeframe,MaPeriod,0,MaType,PRICE_CLOSE,bar+1);

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

{

if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;

if(OrderMagicNumber()!= MAGIC) continue;

if(OrderSymbol() != s_symbol) continue;

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

//| Close BUY |

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

if(cl_diCustom0!=cl_diCustom1) // Check trend

{

if(OrderType()==OP_BUY)

{

if(cl_diCustom0<cl_diCustom1 && cl_diCustom2=cl_diMA4)

{

bool buyClose=OrderClose(OrderTicket(),OrderLots(),MarketInfo(s_symbol,MODE_BID),Slippage*pipMultiplier,clCloseBuy);

if(buyClose==false)

{

int ErrorCode = GetLastError();

string ErrDesc = ErrorDescription(ErrorCode);

string ErrAlert= StringConcatenate("Close Buy Order - Error ",ErrorCode,": ",ErrDesc);

if(ShowAlerts == true) Alert(ErrAlert);

string ErrLog=StringConcatenate("Bid: ",MarketInfo(s_symbol,MODE_BID)," Lots: ",OrderLots()," Ticket: ",OrderTicket());

Print(ErrLog);

}

break;

} // mod

}

}

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

//| Close SELL |

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

if(cl_diCustom0!=cl_diCustom1)

{

if(OrderType()==OP_SELL)

{

if(cl_diCustom0>cl_diCustom1 && cl_diCustom2>cl_diMA3 && cl_diCustom3<=cl_diMA4)

{

bool sellClose= OrderClose(OrderTicket(),OrderLots(),MarketInfo(s_symbol,MODE_ASK),Slippage*pipMultiplier,clCloseSell);

if(sellClose == false)

{

ErrorCode = GetLastError();

ErrDesc = ErrorDescription(ErrorCode);

ErrAlert=StringConcatenate("Close Sell Order - Error ",ErrorCode,": ",ErrDesc);

if(ShowAlerts==true) Alert(ErrAlert);

ErrLog=StringConcatenate("Ask: ",MarketInfo(s_symbol,MODE_ASK)," Lots: ",OrderLots()," Ticket: ",OrderTicket());

Print(ErrLog);

}

break;

} // mod

}

}

}

}

Files:
 
tfi_markets:
Hello Pro-Coders,

I am wondering if someone could review the "Close BUY" and "Close SELL" algorithm.

The EA is not opening new position after stop loss or trend change has taken place.

The system is just closing the position, next position will be opend on new trend change, which leads into loss of opportunity.

(Please see screenshot).

Change this :

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

to this

for(int i=OrdersTotal()-1;i>=0 ; i--)

 
mladen:
Let us know what happened Maybe just a problem of a specific metatrader build (I use build 788 currently)

mine build 765

Pruchik provided this version here,

https://www.mql5.com/en/forum/173588

but needs extra script to remove the lines of the Gann sq9 indicator if it is changed leaving lines on the chart.

 

need help for this display info issue......

vegadigitalco:
Hello Mladen & All senior Codder

need help for this display info issue......

not getting live quote please help

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

//| expert initialization function |

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

#property indicator_chart_window

double ExtMapBuffer1[];

extern int RSI_periode = 14;

extern int RSI_level = 50;

extern color BuyColor = clrLime;

extern color SellColor = clrRed;

extern int horizontal = 20;

extern int vertical = 50;

extern int shift = 1;

extern double percent = 0.25;

extern string fontmode = "Arial";

extern int fontsize = 10;

extern color fontcolor = clrSkyBlue;

extern int columnspacing = 100;

int init()

{

//----

SetIndexStyle(0,DRAW_LINE);

SetIndexBuffer(0,ExtMapBuffer1);

//----

return(0);

}

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

//| expert deinitialization function |

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

int deinit()

{

//----

ObjectsDeleteAll();

ObjectDelete("INFO");

//----

return(0);

}

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

//| expert start function |

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

int start()

{

//----

string symlist2[] = {"NIFTY","B.NIFTY","XAUUSD", "GOLD"};

string symbol;

string info2[] = {MODE_HIGH,MODE_LOW,MODE_BID,MODE_ASK};

string infolabel;

string timeText[] = {"DayHigh","DayLow","Bid","Ask"};

string font = "Terminal";

int counted_bars=IndicatorCounted();

int symlimit = ArraySize(symlist2);

int timelimit = ArraySize(info2);

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

{

symbol = symlist2;

Display("symlabel" + symbol + i, horizontal,vertical);

ObjectSetText("symlabel" + symbol + i, "SYMBOL", fontsize, font, Pink);

Display("sym" + symbol + i, horizontal,vertical +((i+1)*18));

ObjectSetText("sym" + symbol + i, "" + symbol + "", fontsize, font, Yellow);

for(int j=0;j<timelimit;j++)

{

infolabel = info2[j];

Display("infolabel" + j, horizontal+((j+1)*100),vertical);

ObjectSetText("infolabel" + j, timeText[j], fontsize, font, Pink);

Display("infolabel2" + symbol + ((j+1)*columnspacing), horizontal+((j+1)*100),vertical +((i+1)*18));

ObjectSetText("infolabel2" +symbol+ ((j+1)*columnspacing), infolabel , fontsize, font, fontcolor);

}

}

//----

return(0);

}

void Display(string name, int x, int y)

{

ObjectCreate(name, OBJ_LABEL, 0, 0, 0);

ObjectSet(name, OBJPROP_CORNER, 0);

ObjectSet(name, OBJPROP_XDISTANCE, x);

ObjectSet(name, OBJPROP_YDISTANCE, y);

ObjectSet(name, OBJPROP_BACK, FALSE);

}
 

Hi Guys i have a small request.. i `ve been trying to write a function that read from a text file and return its values into a string array..the text file is formed by several lines each of them is a pair name except the first line that is the total number of pairs

For ex:

7

CADJPY

CHFJPY

EURJPY

GBPJPY

NZDJPY

USDJPY

AUDJPY

i found on metaquotes website the following code but im stuck..i`d like to create a string array and after i read the first line in the text resize it to this value and then fill it with the pairs name...can some one help me out pretty please!?

int handle, NL,i,pos[];

string str,word;

handle=FileOpen("test.txt",FILE_READ);//try to open file

if(handle==-1)return(0);// if not exist

if(FileSize(handle)==0){FileClose(handle); return(0); } //if empty

while(!FileIsEnding(handle))//read file to the end by paragraph. if you have only one string, omit it

{

str=FileReadString(handle);//read one paragraph to the string variable

if(str!="")//if string not empty

{

NL=0;

for(i=0;i<StringLen(str);i++)

{

if(StringGetChar(str,i)==10)// look for newline (Charcode:10) only

{

NL++;//yes, we found one more newline

ArrayResize(pos,NL);//increase array

pos[NL-1]=i;//write the number of newline position to array

}

}//now we have array with numbers of positions of all newline

for(i=0;i<=NL;i++)//start to read elements of string

{

if(i==0) word=StringSubstr(str,0,pos[0]);//the first element of string (in this case is the number 7)

else word=StringSubstr(str,pos+1,pos-pos-1);

}

}

}

FileClose(handle); //close file

return(0);

 
download38:
Hello master coder,

I am try to write an PPO_alt indicator which is plot 1 in pictures a and b but it is not plot correctly in the realtime mode

so I try to modify the orignal PPO (plot 2) but it is still not correctly too. Please take a look and could you fix both of them.

Thanks in advance.

PS. Please ask more questions if it is not clear to you.

Could anyone explain the different between for(i=0; i=0; i--) and when we are using them?

Thanks in advance.

Reason: