string PriceToStr(double p){ return( DoubleToStr(p, Digits) ); } : datetime OOT = OrderOpenTime(); // Assumes OrderSelect() done already int iOOT = iBarShift(NULL,0, OOT); // Bar of the open. #define iBarCURRENT 0 // Include current bar. int nSince = iOOT - iBarCURRENT + 1; // No. bars since open. int iHi = iHighest(NULL,0, MODE_HIGH, nSince, iBarCURRENT); double HH = High[iHi]; // Highest high. Print( "High since order opened on ", TimeToStr(OOT)," is ", PriceToStr(HH) );
Here are some errors for the above code.
'(' - function definition unexpected D:\Program Files\FXDD Malta - MetaTrader 4\experts\test2.mq4 (343, 18)
this error for string PriceToStr(double p)
for this error i do not know how can i fix it
'iBarCurrent' - variable not defined D:\Program Files\FXDD Malta - MetaTrader 4\experts\test2.mq4 (348, 30)
this error because you define #define iBarCURRENT then you put it as iBarCurrent
i will fix it.
2 error(s),
Put this line at the very end of your Code outside of the start function . . .
string PriceToStr(double p){ return( DoubleToStr(p, Digits) ); }
and start reading this if you want to learn to code: https://book.mql4.com//
It is clear guys ( RaptorUK and WHRoeder ),
Thank you.
datetime OOT = OrderOpenTime(); // Assumes OrderSelect() done already int iOOT = iBarShift("EURUSD",PERIOD_H1, OOT); // Bar of the open. #define iBarCURRENT 0 // Include current bar. int nSince = iOOT - iBarCURRENT + 1; // No. bars since open. int iHi = iHighest("EURUSD",PERIOD_H1, MODE_HIGH, nSince, iBarCURRENT); double HH = High[iHi]; // Highest high. int iLi = iLowest("EURUSD",PERIOD_H1, MODE_LOW, nSince, iBarCURRENT); double LL = Low[iLi]; // Lowest low.
I have other question:
if i have 2 orders were opened one for buy and the other for sell:
how can I let my EA understand and take the iOOT = iBarShift("EURUSD",PERIOD_H1, OOT); // Bar of the open. For the bar that i got buy position from it and calculate the highest from that point.
And
Take the iOOT = iBarShift("EURUSD",PERIOD_H1, OOT); // Bar of the open. For the bar that i got sell position from it and calculate the lowest from that point.
Many thanks
for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if ( OrderSelect(pos, SELECT_BY_POS) // Only my orders w/ && OrderMagicNumber() == magic.number // my magic number && OrderSymbol() == Symbol() // and my pair. ){ datetime OOT = OrderOpenTime(); // Assumes OrderSelect() done already int iOOT = iBarShift("EURUSD",PERIOD_H1, OOT); // Bar of the open. #define iBarCURRENT 0 // Include current bar. int nSince = iOOT - iBarCURRENT + 1; // No. bars since open. if (OrderType == OP_BUY){ int iHi = iHighest("EURUSD",PERIOD_H1, MODE_HIGH, nSince, iBarCURRENT); double HH = High[iHi]; // Highest high. } else{ int iLi = iLowest("EURUSD",PERIOD_H1, MODE_LOW, nSince, iBarCURRENT); double LL = Low[iLi]; // Lowest low. } }
To get OOT you must have already done an orderSelect
Thanks guys.
Also i have other quesition:
How can i do this conditions: if (last OrderClosePrice() for sell > before the last OrderClosePrice for sell ) && ( before the last OrderClosePrice for sell >= bid)
close the position
is something like this will be ok
if ( (OrderType == OP_SELL)&& OrderSelect(pos+1, SELECT_BY_POS,MODE_TRADES ) ) { if( pos>pos+1 && pos+1>MarketInfo("EURUSD",MODE_BID); // close the position
Just,
I want to know how can i get: the order before the last order(open or close)price() for (buy or sell) to added them for some claculations.
Many thanks.
I want to know how can i get: the order before the last order(open or close)price() for (buy or sell) to added them for some claculations.
for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if ( OrderSelect(pos, SELECT_BY_POS) // Only my orders w/ && OrderMagicNumber() == magic.number // my magic number && OrderSymbol() == Symbol() // and my pair. ){ datetime OOTlatest = OrderOpenTime(); // found latest open order break; } for(pos--; pos >= 0 ; pos--) if ( OrderSelect(pos, SELECT_BY_POS) // Only my orders w/ && OrderMagicNumber() == magic.number // my magic number && OrderSymbol() == Symbol() // and my pair. ){ datetime OOTprevious = OrderOpenTime(); // found the previous break; } if (OOTlastest == 0) // no open orders if (OOTprevious == 0) // no previous :
Thanks WHRoeder,
For your real help. if i need to get the last order for buy and the last order for sell then compare them by doing :
if ( the last orderopenforbuy == OOTlastest )
{ do something }
else
{ } ....... is the below code will work.
for(int pos = OrdersTotal()-1; pos >= 0 ; pos--) if ( OrderSelect(pos, SELECT_BY_POS) // Only my orders w/ && OrderMagicNumber() == magic.number // my magic number && OrderSymbol() == Symbol() // and my pair. ){ if (OrderType() == OP_BUY){ int lastorderforbuy= OrderOpenPrice(); } else{ int lastorderforsell= OrderOpenPrice(); } } for(pos--; pos >= 0 ; pos--) if ( OrderSelect(pos, SELECT_BY_POS) // Only my orders w/ && OrderMagicNumber() == magic.number // my magic number && OrderSymbol() == Symbol() // and my pair. ){ if (OrderType() == OP_BUY){ int previousorderforbuy= OrderOpenPrice(); } else{ int previousorderforsell= OrderOpenPrice(); } } if ( ((lastorderforbuy+ previousorderforsell)/2)<=MarketInfo("EURUSD",MODE_BID)) { CLOSESHORT("EURUSD") ;}
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Dears,
can somebody check the below link and answer my quetion(how can i get the highest after orderopenprice was opened).
http://www.forexfactory.com/showthread.php?t=307937