simple code to modify stop loss and take profits on open trades

 

How can I change this code so that it will work for multiple orders? thanks




int init()
{
start();
return(0);
}

int deinit()
{
start();
return(0);
}


//+------------------------------------------------------------------+
//| script "modify first market order" |
//+------------------------------------------------------------------+
int start() //| expert start function but its not an expert
{
bool result;
double stop_loss,take_profit,point;
int cmd,total,error;
//----
total=OrdersTotal();
point=MarketInfo(Symbol(),MODE_POINT);
//----
for(int i=0; i<total; i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
//---- print selected order
OrderPrint();
cmd=OrderType();
//---- buy or sell orders are considered
if(cmd==OP_BUY || cmd==OP_SELL)
{
//---- modify first market order
while(true)
{
if(cmd==OP_BUY) stop_loss=Bid-60*point; // on 4/13/11 I changed 20 to 40
else stop_loss=Ask+60*point; // on 4/13/11 I changed 20 to 40

//i wrote this part:
if(cmd==OP_BUY) take_profit=Bid+45*point;
else take_profit=Ask-45*point;


result=OrderModify(OrderTicket(),0,stop_loss,take_profit,0,CLR_NONE);
if(result!=TRUE) { error=GetLastError(); Print("LastError = ",error); }
else error=0;
if(error==135) RefreshRates();
else break;
}
//---- print modified order (it still selected after modify)
OrderPrint();
break;
}
}
else { Print( "Error when order select ", GetLastError()); break; }
}
//----
return(0);
}
 
I Also have an idea to develop this kind of EA, which have control loss startegy, it need differnent and seperate layer of TP for different losses, however it seems to be fail, because my EA choose Weak market to enter, that is channel EA, it made be work when the market is stronger
 

this code originally came from a SCRIPT

I just threw in the "start();" in the init and deinit procedures to try to turn it into an EA

I have never used MQL language before!

Am I doing it right? or is it gonna crash and I'm gonna get the M$ BSoD? haha



int init()
{
start();
return(0);
}

int deinit()
{
start();
return(0);
}

 

can someone help me edit sar ohlc to use heiken ashi ohlc

Hi, I have an MTF indicator that uses sar, however I'd like the sar to calculate heiken ashi ohlc, and not the normal type

Can you tell me how I can do this, my mtf indicator calls to the sar indicator to calculate sar formula, I think it is calling to the internal indicator in mt4 that can not edit

you can skype or email if you can assist and like to talk about it

skype sty671

email sty671@gmail.com

I can also supply the original file that I'm trying to use heiken ashi ohlc for

 

ezrollin:

Am I doing it right? or is it gonna crash and I'm gonna get the M$ BSoD? haha


int init()
{
start();
return(0);
}

int deinit()
{
start();
return(0);
}

  1. Do not call start, mql4 will call it once per tick.
  2. Run it in the tester, add print statements so you can figure out what it is doing. If you can't figure how to get it to do what you want, post the code and the question.
 
sty671:

can someone help me edit sar ohlc to use heiken ashi ohlc

  1. Don't hijack other peoples threads.
  2. No slaves here, learn to code or pay someone.
  3. Don't post the same exact question five plus times.
 

How does a stop loss order can be moved to follow the candle? please help,

thank you.

 
  1. Don't hijack other peoples threads.
  2. Don't post the same exact question multiple times
  3. Asked and answered on the other thread - OrderModify()