to use OrderOpenPrice() Order must be first selected by the OrderSelect() function.
Yes, I agree, the function maxvalue() would be called on checking if a long position should be closed after:
for(cnt=0;cnt<total;cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if(OrderType()<=OP_SELL && // check for opened position OrderSymbol()==Symbol() && // check for symbol OrderMagicNumber() == MAGICMA)// check for magic number { if(OrderType()==OP_BUY) // long position is opened { // should it be closed?
I guess it would be correct.
But what I don't know is if the functions code I mentioned maxvalue() and minvalue() should work correctly.
I do not understand what you are trying to accomplish
if(Current_low < Previous_low) //if current low is lower than previous bars low, { Previous_low = Current_low;
Previous_low must be declared static.Current_low = Low[0]; Previous_low = Current_low;
This invalidate Previous_low- Is this code correct to calculate the maximum or minimum price achived by a position
Why not count=IBarShift(OrderOpenTime()); H=High[Highest(count+1,0)]
-
Previous_low must be declared static.
-
This invalidate Previous_low
- Is this code correct to calculate the maximum or minimum price achived by a position
Why not count=IBarShift(OrderOpenTime()); H=High[Highest(count+1,0)]
Does it returns the maxprice or minprice the open position achieved? To code a trailingstop I need to know what was the max or min price an open position achieved in order to close the position if the price moves back a certain amount in the direction of the OpenPrice.
Thanks for the help.
Best regards.
int OpenBar=iBarShift(NULL,1,OrderOpenTime(),false); // the bar at which the order was opened int CloseBar=0; // Assume the selected order is still open, verify assumption in next step // if(OrderCloseTime()!=0) CloseBar=iBarShift(NULL,1,OrderCloseTime(),false); // This captures a closed order such that the searched bar range is the correct span of time // int LowestBar=iLowest(NULL,1,MODE_LOW,OpenBar-CloseBar+1,CloseBar); // find the bar that had the lowest market price int HighestBar=iHighest(NULL,1,MODE_HIGH,OpenBar-CloseBar+1,CloseBar); // find the bar that had the highest market price // double Minimum_Price = iLow(NULL,1,LowestBar); // the lowest market price that occurred in the timespan of the order double Maximum_Price = iHigh(NULL,1,HighestBar); // the highest market price that occurred in the timespan of the orderThe caveat with this code is the high and low prices for the opening bar are considered "viable" price extremes when that could possibly be false. For instance if you opened a trade in an M1 candle after the low price for that candle had already been reached and it turned out that the low price of that position-opening bar also happened to be the lowest price the market reached over the ensuing lifespan of the position then the above code would capture that opening bar low value and assume it was the lowest price the trade had experienced (which wouldn't be true).
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Is this code correct to calculate the maximum or minimum price achived by a position? I Used OrderOpenPrice to verifiy if a position is opened. From this max e min values I would like to code a trailing stop. Is it possible?
Best regards.