... This is after I've removed function init, deinit and comments to make it more clear...
externdouble TakeProfit=350.0;
externdouble Lots=0.1;
externdouble TrailingStop=0.0;
externbool Test=false;
externint Nbr_Periods=10;
externdouble Multiplier=3.0;
int c_altBars=0;
bool b_trade=false;
bool b_print=false;
//+------------------------------------------------------------------+//| expert start function |//+------------------------------------------------------------------+int start()
{
int cnt, ticket, total, isCrossed;
if (Bars<100) {
Print("bars less than 100");
return (0);
}
if (c_altBars < Bars)
{
c_altBars = Bars;
// only for test purposesdouble sT_5 = iCustom(NULL,0,"Heiken Ashi and TK1",Nbr_Periods,Multiplier,7,5);
double sT_4 = iCustom(NULL,0,"Heiken Ashi and TK1",Nbr_Periods,Multiplier,7,4);
double sT_3 = iCustom(NULL,0,"Heiken Ashi and TK1",Nbr_Periods,Multiplier,7,4);
double sT_2 = iCustom(NULL,0,"Heiken Ashi and TK1",Nbr_Periods,Multiplier,7,2);
double sT_0 = iCustom(NULL,0,"Heiken Ashi and TK1",Nbr_Periods,Multiplier,7,0);
// changeTrend[1] in indicator; buffer7[1] is trade trigger in EAdouble sT_1 = iCustom(NULL,0,"Heiken Ashi and TK1",Nbr_Periods,Multiplier,7,1);
Alert(Bars+" "+sT_5+" "+sT_4+" "+sT_3+" "+sT_2+" "+sT_1+" "+sT_0+" "+TimeToStr(Time[0]));
if (sT_1 == 1.38)
{
isCrossed = 1; Print ("Crossed = 1 "+" "+TimeToStr(Time[0]));
}
elseif (sT_1 == 1.42)
{
isCrossed = 2; Print ("Crossed = 2"+" "+TimeToStr(Time[0]));
}
else isCrossed = 0;
if (Test == false) b_trade = true;
else b_trade = false;
total=OrdersTotal();
if(total<1)
{
if(isCrossed ==1 && b_trade == true) {
isCrossed = 0;
b_trade = false;
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,1,0,0,"ADI EA",12345,0,Green);
if(ticket>0) {
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
Print("BUY order opened: ",OrderOpenPrice());
}
elsePrint("Error openning BUY order: ",GetLastError());
return (0);
}
if(isCrossed==2 && b_trade == true) {
isCrossed = 0;
b_trade = false;
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,1,0,0,"ADI EA",12345,0,Red);
if(ticket>0) {
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
Print("SELL order opened: ",OrderOpenPrice());
}
elsePrint("Error openning SELL order: ",GetLastError());
return (0);
}
return (0);
}
for(cnt=0;cnt<total;cnt++) {
OrderSelect(cnt, SELECT_BY_POS,MODE_TRADES);
if(OrderType()<=OP_SELL && OrderSymbol()==Symbol()) {
if(OrderType()==OP_BUY) { //long position is openedif(isCrossed==2 && b_trade == true) { // should be closed?
isCrossed = 0; b_trade = false;
// close long position
OrderClose(OrderTicket(),OrderLots(),Bid,1,Violet); // close position// and open short position
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,1,0,0,"ADI EA",12345,0,Red);
if(ticket>0) {
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
Print("SELL order opened: ",OrderOpenPrice());
}
elsePrint("Error openning SELL order: ",GetLastError());
return(0); // exit
}
// check for trailing stop, by buy trendif(TrailingStop>0) {
if(Bid-OrderOpenPrice()>Point*TrailingStop) {
if(OrderStopLoss()<Bid-Point*TrailingStop) {
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
return(0);
}
}
}
}
else { // go to short positionif(isCrossed==1 && b_trade == true) { // should be closed?
isCrossed = 0; b_trade = false;
// close short position
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); //close position// and open long position
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,1,0,0,"ADI EA",12345,0,Green);
if(ticket>0) {
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
Print("BUY order opened: ",OrderOpenPrice());
}
elsePrint("Error openning BUY order: ",GetLastError());
return(0); // exit
}
// chack for trailing stop, by sell trendif(TrailingStop>0) {
if(OrderOpenPrice()-Ask>Point*TrailingStop) {
if((OrderStopLoss()>(Ask-Point*TrailingStop)) || (OrderStopLoss()==0)) {
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
}
} // eimal pro Periodereturn(0);
}
Now, can you please describe what exactly this EA is trying to achieve? I have the idea from your code but I want to make sure what you're intending to achieve...
trade trigger (buffer7[1] of the indicator) in the EA delivers wrong values. The buffer7 in indicator (see white line in chart and output listing) delivers correct values.
Conclusion/main question:
Why function "double sT_1 = iCustom(NULL,0,"Heiken Ashi and TK1",Nbr_Periods,Multiplier,7,1" delivers wrong values (see output listing)?
the debugging Print uses these block. changeTrend is your focus right?
if (trend[i]==1) {
TrendUp[i]=dn[i];
if (changeOfTrend == 1) {
TrendUp[i+1] = TrendDown[i+1];
changeOfTrend = 0;
changeTrend[i] = 1.38; // changeTrend-Buffer for EA application(LONG) Print(TimeToStr(Time[i])+": "+changeTrend[i]+" "+i+" long "+Bars);
}
}
elseif (trend[i]==-1) {
TrendDown[i]=up[i];
if (changeOfTrend == 1) {
TrendDown[i+1] = TrendUp[i+1];
changeOfTrend = 0;
changeTrend[i] = 1.42; // changeTrend-Buffer for EA application (SHORT)Print(TimeToStr(Time[i])+" "+changeTrend[i]+" "+i+" short "+Bars);
}
}
Notice that both print debugging of your indicator happens inside this loop header, so it always print them starting from i=Bars and finishes at i=0
for (i = Bars; i >= 0; i--) {
while on your EA, your alert debug prints not within any loop and always printing bar index 0 to 5 :
double sT_1 = iCustom(NULL,0,"Heiken Ashi and TK1",Nbr_Periods,Multiplier,7,1);
Print(Bars+" "+sT_5+" "+sT_4+" "+sT_3+" "+sT_2+" "+sT_1+" "+sT_0+" "+TimeToStr(Time[0]));
This print values u see from your indicator only able to display few bars values from the oldest bar when new ticks arrive and rewrites them with new values all over again. Never reaching or displaying latest bar values you wanted to see, i.e. 0 to 5.
So you're comparing head's values to tail's values. Try comparing the EA alert values to values in DataWindow instead (hover your mouse over the latest bars). It matches. changeTrend values is 1.40 up to bar index 32 (I use H1). So iCustom calls them fine.
This is why I recommend you to re-read the documentation to have solid grasp of program flow.
You don't have clear program flow. Every buffer must be filled before you make decision on it. You can't make decision on iteration!
I can explain where you made your mistake exactly but that would mean re-writing it for you. Try to understand my last hint in bold. There's nothing wrong with iCustom. There's definitely something wrong with your program's logical flow.
- Buffer7 is filled (mostly with 1.4, occasionally with trigger 1.38 or 1.42) in indicator correct in time. In EA per new bar I would like to find trade trigger from the buffer7. Where is decision on iteration?
- EA with tick easier indicator but with same program flow (see source code below) works full correct.
I don't expect that you re-writing my program. If you exactly know, where I made mistake. Then you should indicate the source of error. This is the forum aim.
Oh, boy.... Ok, so you only wrote the EA, the SuperTrend was not written by you, correct? The problem lies in the iteration of SuperTrend.
Let me rephrase this : I can explain where you made your mistake exactly but that would mean re-writing it for you -- > means : To sort it out exactly would be to re-write the indicator.
It is recounting every bars on every tick. All other is a bold statement without proof. You're making me doin' it, aren't you :)
I'm not understand your argumentation. The easier indicator (one step- exact the same SuperTrend, without Heiken Ashi-see source code above) works with the same EA correct.
Consequently: Why should I change interation of SuperTrend, if it works in the same EA correct?
Your sentence is wrong, not oldetsbut youngest (see above):
This print values u see from your indicator only able to display few
bars values from the oldest bar when new ticks arrive and rewrites them
with new values all over again.
mql7, It's like when someone says 'Oh, lord...' they don't call someone a lord. it's just an interjection. I'm not calling you a boy or anything.
I made the wrong assumption of you being the author of SuperTrend. So, obviously that was wrongly addressed, my bad.
I'm convinced you really needed this, so I will help you as best as I can. Just give me some time to finish off some work. I don't promise a quick response, but I'll help you sort this out.
No, the sentence is correct. When you have decrementing loop :
for (i = Bars; i >= 0; i--) {
and inside that loop you print or do something that uses that decrementing index, you will start with index Bars, which is the oldest bars. and work your way down to the youngest bar indexed 0.
So the youngest bar never had a chance to get displayed at least on my observation.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Well, let's go over them step by step if you really want to get them right...
This is what you've attached....... This is after I've removed function init, deinit and comments to make it more clear...
Now, can you please describe what exactly this EA is trying to achieve? I have the idea from your code but I want to make sure what you're intending to achieve...
I repeat (see quite above),
trade trigger (buffer7[1] of the indicator) in the EA delivers wrong values. The buffer7 in indicator (see white line in chart and output listing) delivers correct values.
Conclusion/main question:
Why function "double sT_1 = iCustom(NULL,0,"Heiken Ashi and TK1",Nbr_Periods,Multiplier,7,1" delivers wrong values (see output listing)?
Oh, my bad. Ok I tested them. Notice this :
the debugging Print uses these block. changeTrend is your focus right?
Notice that both print debugging of your indicator happens inside this loop header, so it always print them starting from i=Bars and finishes at i=0
while on your EA, your alert debug prints not within any loop and always printing bar index 0 to 5 :This print values u see from your indicator only able to display few bars values from the oldest bar when new ticks arrive and rewrites them with new values all over again. Never reaching or displaying latest bar values you wanted to see, i.e. 0 to 5.
So you're comparing head's values to tail's values. Try comparing the EA alert values to values in DataWindow instead (hover your mouse over the latest bars). It matches. changeTrend values is 1.40 up to bar index 32 (I use H1). So iCustom calls them fine.
I use D1,
values in EA are unambiguously wrong!!!. See please the time information 9. - 11.11.2010 by print debugging in. There entry 1.42000000 is absent.
Position i=0 10.11.2010 and i=1 11.11.2010 must be 1.42000000
This is why I recommend you to re-read the documentation to have solid grasp of program flow.
You don't have clear program flow. Every buffer must be filled before you make decision on it. You can't make decision on iteration!
I can explain where you made your mistake exactly but that would mean re-writing it for you. Try to understand my last hint in bold. There's nothing wrong with iCustom. There's definitely something wrong with your program's logical flow.
I don't state, that function iCustom works wrong!
Clarification:
- Buffer7 is filled (mostly with 1.4, occasionally with trigger 1.38 or 1.42) in indicator correct in time. In EA per new bar I would like to find trade trigger from the buffer7. Where is decision on iteration?
- EA with tick easier indicator but with same program flow (see source code below) works full correct.
I don't expect that you re-writing my program. If you exactly know, where I made mistake. Then you should indicate the source of error. This is the forum aim.
All other is a bold statement without proof.
Thank you for help!!!
Oh, boy.... Ok, so you only wrote the EA, the SuperTrend was not written by you, correct? The problem lies in the iteration of SuperTrend.
Let me rephrase this : I can explain where you made your mistake exactly but that would mean re-writing it for you -- > means : To sort it out exactly would be to re-write the indicator.
It is recounting every bars on every tick. All other is a bold statement without proof. You're making me doin' it, aren't you :)
I'm not boy but girl.
I'm not understand your argumentation. The easier indicator (one step- exact the same SuperTrend, without Heiken Ashi-see source code above) works with the same EA correct.
Consequently: Why should I change interation of SuperTrend, if it works in the same EA correct?
Your sentence is wrong, not oldets but youngest (see above):
This print values u see from your indicator only able to display few bars values from the oldest bar when new ticks arrive and rewrites them with new values all over again.
mql7, It's like when someone says 'Oh, lord...' they don't call someone a lord. it's just an interjection. I'm not calling you a boy or anything.
I made the wrong assumption of you being the author of SuperTrend. So, obviously that was wrongly addressed, my bad.
I'm convinced you really needed this, so I will help you as best as I can. Just give me some time to finish off some work. I don't promise a quick response, but I'll help you sort this out.
No, the sentence is correct. When you have decrementing loop :
and inside that loop you print or do something that uses that decrementing index, you will start with index Bars, which is the oldest bars. and work your way down to the youngest bar indexed 0.
So the youngest bar never had a chance to get displayed at least on my observation.