How to code? - page 34

 

Need help to edit part of EuroX2_sl EA .......

Hi all Programmers,

I am new to forex trade and new to this forum too. First time, I am learning is 10 points 3 then, EuroX2_sl, extended from 10 points 3 EA script. After did a few forward test, for me this EA is quite ok to newbie like me to learn. When forward test, it did Open Position well but it did not Close Position as I need ( even i already condition ) when market reverse or when the trend change. Maybe, something is wrong with the code ( cos' I am not a programmer ) and I think I need help from anyone of you to solve it. Could please check which part may be wrong ?

I think OPEN position is okay as it make profit but the problem is with the CLOSE POSITION as it did not CLOSE ( BUY or SELL ) even when the indicator exist and this make the floating losses quite much.......

Anyone who knew about this, please help me edit this code.......

The code as I did is :

-------- part of script from EuroX2_sl extended from 10 points 3 as I think is for close position -------

//+--------------------------------------------------------

// it is important to enter the market correctly,

// but it is more important to exit it correctly...

for(cnt=0;cnt<total;cnt++)

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if(OrderType()<=OP_SELL && // check for opened position

OrderType()<=OP_BUY &&

OrderType()>=OP_SELL &&

OrderType()>=OP_BUY &&

OrderSymbol()==Symbol()) // check for symbol

{

//+--------------------------------------------------------------

if(OrderType()==OP_BUY) // long position is opened

{

//+-------------------------------------------------------------------

//+ CONDITION FOR CLOSE POSITION

//+-------------------------------------------------------------------

//+--------------- CLOSE BUY POSITION ----------------------------

if ( Stoch_Main_M15_Cu < Stoch_Sig_M15_Cu )

//+ stochastic main < stochastic signal

//+------------------------------------------------------------------

{

OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet) ; // close position

return(0); // exit

}

//+-----------------------------------------------------------------------

// check for trailing stop

if(TrailingStop>0)

{

if(Bid-OrderOpenPrice()>Point*TrailingStop)

{

if(OrderStopLoss()<Bid-Point*TrailingStop)

{

OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);

return(0);

}

}

}

}

//+---------------CLOSE SELL POSITION --------------------------------

else // go to short position

{ //+ DO NOT REMOVE

if(OrderType()==OP_SELL) // short position is opened

{

}

// should it be closed?

//+----------------------------------------------------------------------------

if ( Stoch_Main_M15_Cu > Stoch_Sig_M15_Cu )

//+ stochastic main > stochastic signal

//+-----------------------------------------------------------------------------

{

OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet) ; // close position

return(0); // exit

}

//+----------------------------------------

// check for trailing stop

if(TrailingStop>0)

{

if((OrderOpenPrice()-Ask)>(Point*TrailingStop))

{

if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))

{

OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Poi nt*TrailingStop,OrderTakeProfit(),0,Red);

return(0);

}

}

}

}

}

}

--------------------------------------------------------------

Thank you,

fxgroup

 

What are the best weekly/daily term indicators

This question could be directed to experienced traders.

Which are the reliable (Already tested) indicators that could give us an idea about the main trend move during:

1- Future week

2- Future day (Or next Day)

Knowing that I am not asking for B/S entry levels.

Note: I think once we define the move direction for next week, we can build a base for when to enter.

Thanks

 

mql question

Code:

// if we have opened positions we take care of them

//with modifying stoploss

cnt=OrdersTotal();

while(cnt>=0)

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) // && Reversed==False)

{

Print("Ticket ",OrderTicket()," modified.");// why is it written here before modifying orders (as i understand it)?

if (OrderType()==OP_SELL)

{

if (TrailingStop>0)

{

if ((OrderOpenPrice()-Ask)>=(TrailingStop*Point+Pips*Point))

{

if (OrderStopLoss()>(Ask+Point*TrailingStop) || OrderStopLoss()==0)

{

OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderClosePrice()-TakeProfit*Point-TrailingStop*Point,0,Purple);

return(0);

Hello every body, could someone explain me why :Print("Ticket ",OrderTicket()," modified."); is written before modifying the order. As iunderstand it, it will print "order ticket modified" even if it hasnot been modified. It's a piece of terminator code.

Thank you.

 
Flytox:
Code:

// if we have opened positions we take care of them

//with modifying stoploss

cnt=OrdersTotal();

while(cnt>=0)

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) // && Reversed==False)

{

Print("Ticket ",OrderTicket()," modified.");// why is it written here before modifying orders (as i understand it)?

if (OrderType()==OP_SELL)

{

if (TrailingStop>0)

{

if ((OrderOpenPrice()-Ask)>=(TrailingStop*Point+Pips*Point))

{

if (OrderStopLoss()>(Ask+Point*TrailingStop) || OrderStopLoss()==0)

{

OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderClosePrice()-TakeProfit*Point-TrailingStop*Point,0,Purple);

return(0);

Hello every body, could someone explain me why :Print("Ticket ",OrderTicket()," modified."); is written before modifying the order. As iunderstand it, it will print "order ticket modified" even if it hasnot been modified. It's a piece of terminator code.

Thank you.

You are right, should be wrote after modification or the message should be : "Trying to modify order : ",OrderTicket()

 

thank you Kalenzo, i'am learning mql and your articles and answers are very helpful, thanks again.

 

It might be sufficient if you do the following four edits:

1. Comment out line 102, to be

//IsTrade = True;[/PHP]

2. Change blank line 104 to be

if ( Bid > OrderOpenPrice() - GAP * Point ) IsTrade = true;

3. Change blank line 120 to be

[PHP]if ( Ask < OrderOPenPrice() + GAP * Point ) IsTrade = true;

4. Add the "GAP" variable (extern int), which is the set number of pips where the "hedge" should come in.

Though, someone pointed out before somewhere in this forum, that you can't really "hedge" in the same symbol; it's pretty much the same as taking the loss. Perhaps it's better to take the loss and then come back when the price reverses again....

 
ralph.ronnquist:
It might be sufficient if you do the following four edits:

1. Comment out line 102, to be

//IsTrade = True;[/PHP]

2. Change blank line 104 to be

if ( Bid > OrderOpenPrice() - GAP * Point ) IsTrade = true;

3. Change blank line 120 to be

[PHP]if ( Ask < OrderOPenPrice() + GAP * Point ) IsTrade = true;

4. Add the "GAP" variable (extern int), which is the set number of pips where the "hedge" should come in.

Though, someone pointed out before somewhere in this forum, that you can't really "hedge" in the same symbol; it's pretty much the same as taking the loss. Perhaps it's better to take the loss and then come back when the price reverses again....

Didn't help. And, to be more specific, what I am actually wanting my EA to do is the following:

The EA will enter a buy/sell trade based on certain condition. Once The initial trade is entered, it sometimes may take three to five days before it finally closes out at takeprofit. In the meantime, during that three to five day period, there may be several trade opportunities in the opposite direction. I want the EA to take advantage of those opportunities while leaving the original trade open because it will eventually close out in profit. These additional trade opportunities in the opposite direction of the original trade will technically be a hedge against the original trade, even though they will eventually also close out at takeprofit. To be clear though, I still only want the EA to only have one trade open in the same direction. So, the max trades open at the same time would be one buy and one sell.

I hope this helps!

Thanks for your response

 

Hmm; I didn't trial your EA, but by reading the logic, it looks to me like the only thing stopping a subsequent Sell after a Buy is that "IsTrade" is true. (Except that it won't open a Sell at the very same time as it opens a Buy)

So if you want the Sell logic to apply unconditionally, I would have thought that my edit (1) only -- forget 2-4 -- would do the trick. Or remove the "IsTrade" logic.

Though, there's the subordinate logic with "TickCheck" and "BarCount", which stops another trade at the same tick or at the same bar, but I assume you want that to apply still.

Of course I can't say much about the signaling part, which you omitted. E.g., if raising a "Sell_Signal" takes account of "BuyOrders", then there's more to do.

 

Make Coding Intersting

Before You press BACK,would You please help me???

I am new in coding indicators, but I know how to code EA's, though. Not 100%, but good enough.

Anyway, I was wondering if someone kind would help me.

May You please explain each line to me and give me an example.

p.s. It's a part of a code for MACD:

int start()

{

int limit;//what does Limit equal,0?

int counted_bars=IndicatorCounted();

//---- last counted bar will be recounted

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

//---- macd counted in the 1-st buffer

for(int i=0; i<limit; i++)//i<0?

MacdBuffer=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);

//---- signal line counted in the 2-nd buffer

for(i=0; i<limit; i++)

SignalBuffer=iMAOnArray(MacdBuffer,Bars,SignalSMA,0,MODE_SMA,i);

//---- done

return(0);

}

//+------------------------------------------------------------------+

I would be very happy if someone or more people helped me, and gave me hints for coding indicators, or something like that.

Thank You,

Dan.

 

How to run a script inside a EA?

Hi,

I'd like to know how to run a script in script dirctory within a EA.

If (condition true)

{

Run Script;

}

Thx in advance

Regards

Jimmy

Reason: