Hi all,
So, I'm looking to modify an object position like stoploss line in a TrailingStop code.
The object is created in the right place but it do not follow the price. Also it not delete from the chart ( at this moment the Tester chart)
Following is the code that I have to create the object inside the TrailingStop code and also is the code that should delete it.
Are your braces numbered correctly ? if they are your
if(OrderType()==OP_SELL
is outside of your for loop . . . sort your braces, sort your indenting.
The line is only deleted if the OrderClose() fails, if ( ! OrderClode() ) check your code. Move the ObjectDelete outside the if ( ! OrderClode() ) { } braces.
Are your braces numbered correctly ? if they are your
is outside of your for loop . . . sort your braces, sort your indenting.
The line is only deleted if the OrderClose() fails, if ( ! OrderClode() ) check your code. Move the ObjectDelete outside the if ( ! OrderClode() ) { } braces.
Hi RaptorUK,
Thank you for your attention to my issue and sorry to get your time.
I've put out the ObjectDelete form the if(!OrderClose),but the line still there....
Could you tell me where I'm wrong ?
Best regards
Luis
void CloseAll() {//1 int OrdType; int GLError; for(int OrderPos = OrdersTotal()-1; OrderPos >= 0; OrderPos--) if(OrderSelect(OrderPos, SELECT_BY_POS, MODE_TRADES) && OrderMagicNumber()== MagicNumber && OrderSymbol()== Symbol()) {//2 OrdType = OrderType(); if(OrdType == OP_BUY || OrdType==OP_SELL) {//3 while(IsTradeContextBusy()) Sleep(SleepTime); RefreshRates(); if(!OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(),Slippage*pips2points, Red)) GLError = GetLastError(); Print("Error Closing Order, error # ", GLError, " for ticket: ", OrderTicket()); }//3 if(!ObjectDelete("highline")) GLError = GetLastError(); Print("Error Deleting Object, error # ", GLError, " for ticket: ", OrderTicket()); }//2 }//1
luisneves: The object is created in the right place but it do not follow the price. Also it not delete from the chart ( at this moment the Tester chart)
ObjectCreate("highline",OBJ_HLINE,0,0,Bid - TrailingStop * pips2dbl); ObjectSet("highline",OBJPROP_COLOR,Yellow); ObjectSet("highline",OBJPROP_WIDTH,1);
- Once the line is created, the Create command will fail. You are not, ever, moving the line. If you want it to move, try my TLine()
- Check your return codes (OrderCreate) What are Function return values ? How do I use them ? - MQL4 forum
Hi RaptorUK,
Thank you for your attention to my issue and sorry to get your time.
I've put out the ObjectDelete form the if(!OrderClose),but the line still there....
. . . and you have broken the error reporting for the OrderClose()
Do you understand the purpose of { } braces ? it seems to me that you don't, but you really need to, if you want to make progress.
Hi RaptorUk,
Thank you for your alert. I'm doing my best to get information how to deal with basic issues regarding the syntax.
Clarify me about this;
The reason that am try to get an object to do the conventional trailing stop is to avoid minimum movement of the stop loss concerning stop level.
Is the above make any sense ?
Thank you in advance
Luis
Hi RaptorUk,
Thank you for your alert. I'm doing my best to get information how to deal with basic issues regarding the syntax.
Clarify me about this;
The reason that am try to get an object to do the conventional trailing stop is to avoid minimum movement of the stop loss concerning stop level.
Is the above make any sense ?
OK, I think I understand . . . is your Freezelevel == 0.0 ?
This is a problem . . .
if( Bid <= PricePosition)CloseAll();
PricePosition is not current at this point in the code, it was read using ObjectGet() before you attempted to move the line. Also read what WHRoeder wrote, before you use ObjectCreate() you should first check if the Object already exists using ObjectFind(), if it doesn't then create it, if it does then just move it using ObjectSet() fix this issue, fix the issue with the braces and indenting, test your code, if it still is not doing what you think it should post the revised code.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi all,
So, I'm looking to modify an object position like stoploss line in a TrailingStop code.
The object is created in the right place but it do not follow the price. Also it not delete from the chart ( at this moment the Tester chart)
Following is the code that I have to create the object inside the TrailingStop code and also is the code that should delete it.
Any clue how to get this working ?
thank you in advance for any help provided
Luis