Free Grid Trading, The New Grid EA - page 9

 

Aren't we all newbies?

JamalJohnson:
Thorup,

I'm a little green, a little wet behind the ears. I hope I don't sound spoiled after your christmas gift alteration to floating center version. I understand if you have a life that doesn't include handouts and freebees. I'm still very glad about the lookbackbars so no hard feelings. Thanks again. You still the man.

Jamal

Hey Jamal.

In terms of trading Forex, if you're green, i'm probably lightgreen. And in terms of coding EA's i'm also lightgreen, i've only tried a few things for the last 3 months without prior knowledge than a little logical thinking (and reading). That, and the busy time of X-mas, is the reasons why I haven't had time to even look at your suggested alterations, although they sound interesting. I hope i'll get to it sometime in the new year.

Happy New Year

Thorup

 

could you make this ea work on ECN mt4

Hi loup could you please help me make this EA send order and pending order with out SL;TP then add it after one second.cause it does not work with mt4 ECN.thank you make this forum very usefull and attractfull.

//---- input parameters

extern double Lots=0.01;

extern int LotDigits=2;

extern double StopDistance =;

extern double TakeProfit =; //0 Means auto calculate profit from StopLoss

extern double StopLoss=;

//extern bool FirstOrderIsLong = true;

bool FirstOrderIsLong = true;

extern int Period_MA = 20;

extern int MagicNumber=999;

extern bool UseHourTrade = false;

extern int StartHourTrade = 6; // start trading on this hour

extern int EndHourTrade = 18; // end trading on this hour

extern bool FiveDigitBroker = true;

extern int TimeFrame = 0;

extern double InitialRisk=4;

//extern int StartHour=0;

//extern int EndHour=24;

int Slippage = 3;

double OpenBuy=0;

double OpenSell=0;

double OpenBuyLimit=0;

double OpenSellLimit=0;

double OpenBuyStop=0;

double OpenSellStop=0;

double EntryPrice=0;

double LastBuyStopPrice=0;

double LastSellStopPrice=0;

double BuyStopPrice=0;

double SellStopPrice=0;

//double aLots[]={1,3,6,12,24,48,96,192,384,768};

//double aLots[]=(0.1, 0.3, 0.9, 2.7, 8.1, 24.3, 72.9, 218.7, 656.1, 1968.3);

double MaxLots=0;

double MA; // MA value on 0 bar

bool Fact_Up = true; // Fact of report that price..

bool Fact_Dn = true; //..is above or below MA

//Trade Signal

#define _NONE 0

#define _BUY 1

#define _SELL 2

#define _CLOSEBUY 4

#define _CLOSESELL 8

#define _OPENBUYSTOP 16

#define _OPENSELLSTOP 32

#define _DELETEBUYSTOP 64

#define _DELETESELLSTOP 128

int cur_signal=_NONE;

static double point;

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

//| expert initialization function |

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

int init()

{

//---- TODO: add your code here

point = Point;

if (FiveDigitBroker)

point = Point * 10;

CheckOpenPositions();

return(0);

}

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

//| expert deinitialization function |

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

int deinit()

{

//---- TODO: add your code here

return(0);

}

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

//| expert start function |

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

int start()

{

double llots;

double lSL;

if (TakeProfit==0) TakeProfit=StopLoss/2;

if (StopDistance!=TakeProfit)

if (StopDistance!=(TakeProfit/2))

return (-1);

if (TimeFrame!=0)

if ((TimeFrame!=PERIOD_M1) && (TimeFrame!=PERIOD_M5) && (TimeFrame!=PERIOD_M15) && (TimeFrame!=PERIOD_M30) && (TimeFrame!=PERIOD_H1) && (TimeFrame!=PERIOD_H4) && (TimeFrame!=PERIOD_D1) && (TimeFrame!=PERIOD_W1) && (TimeFrame!=PERIOD_MN1))

return (-1);

if(MaxLots==0) llots=LotSize(); else

if(MaxLots==LotSize()) llots=3*LotSize(); else

llots=MaxLots*2;

lSL=StopLoss;

CheckSignal();

if(cur_signal & _BUY !=0)

OpenOrder(OP_BUY, llots, Ask, Slippage, lSL, TakeProfit, WindowExpertName(), MagicNumber, 0, Blue);

if(cur_signal & _SELL !=0)

OpenOrder(OP_SELL, llots, Bid, Slippage, lSL, TakeProfit, WindowExpertName(), MagicNumber, 0, Red);

if(cur_signal & _CLOSEBUY !=0)

{

CloseLongs(MagicNumber);

}

if(cur_signal & _CLOSESELL !=0)

{

CloseShorts(MagicNumber);

}

if(cur_signal & _DELETEBUYSTOP !=0)

DeleteOpenOrder(OP_BUYSTOP);

if(cur_signal & _DELETESELLSTOP !=0)

DeleteOpenOrder(OP_SELLSTOP);

if(cur_signal & _OPENBUYSTOP !=0)

{

DeleteOpenOrder(OP_BUYSTOP);

if(FirstOrderIsLong) BuyStopPrice=EntryPrice; else BuyStopPrice=EntryPrice+StopDistance*point;

Print ("First Order Is Long = " + FirstOrderIsLong);

OpenOrder(OP_BUYSTOP, llots, BuyStopPrice, Slippage, lSL, TakeProfit, WindowExpertName(), MagicNumber, 0, Blue);

}

if(cur_signal & _OPENSELLSTOP !=0)

{

DeleteOpenOrder(OP_SELLSTOP);

Print ("Entry Price = " + NormalizeDouble(EntryPrice,Digits));

if(FirstOrderIsLong) SellStopPrice=EntryPrice-StopDistance*point; else SellStopPrice=EntryPrice;

Print ("First Order Is Long = " + FirstOrderIsLong);

OpenOrder(OP_SELLSTOP, llots, SellStopPrice, Slippage, lSL, TakeProfit, WindowExpertName(), MagicNumber, 0, Red);

}

CheckOpenPositions();

HandleOpenPositions();

return(0);

}

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

void CheckSignal()

{

cur_signal=_NONE;

if(OpenBuy==0 && OpenSell==0)

{

if(OpenBuyStop>0) cur_signal |= _DELETEBUYSTOP; if(OpenSellStop>0) cur_signal |= _DELETESELLSTOP;

if(cur_signal==_NONE)

{

// to see if it's possible to made a trade

if(BlockTradingFilter1())

return(0);

MA=iMA(NULL,TimeFrame,Period_MA,0,MODE_SMA,PRICE_C LOSE,0);

if (Bid > MA && Fact_Up == true) // Checking if price above

{

Fact_Dn = true; // Report about price above MA

Fact_Up = false; // Don't report about price below MA

//Alert("Price is above MA(",Period_MA,")."); // Alert

FirstOrderIsLong = true;

}

//--------------------------------------------------------------------

if (Bid < MA && Fact_Dn == true) // Checking if price below

{

Fact_Up = true; // Report about price below MA

Fact_Dn = false; // Don't report about price above MA

//Alert("Price is below MA(",Period_MA,").");// Alert

FirstOrderIsLong = false;

}

if(FirstOrderIsLong) cur_signal |= _BUY; else cur_signal |= _SELL;

EntryPrice=0;

}

}

if(OpenBuy!=0 || OpenSell!=0)

{

if(OpenBuy>OpenSell && OpenSellStop==0)

{

cur_signal |= _OPENSELLSTOP;

}

if(OpenBuy<OpenSell && OpenBuyStop==0)

{

cur_signal |= _OPENBUYSTOP;

}

}

}

 

his EA why not use limit or stop

this EA why not use limit or stop

 

The programming approach is much simpler and the code much faster when orders are simply opened when the desired price values are reached. Using limtis and stops complicates order handling and makes a mess out of the trading statements. I like it a lot more when systems just open and close positions on their own.

 

Hi Thorup,

What setting do I use for Balance Factor to turn off MM?

Thanks,

rb251

 

Turning off MM

rb251:
Hi Thorup,

What setting do I use for Balance Factor to turn off MM?

Thanks,

rb251

Well, if I haven't messed up the programming it should be done by setting MM=false...

 

OOPS, I see it now.

Thanks,

rb251

 

need help

ok i want such a system with a little change i need equity management of 20 persent then only long trades to be taken want to trade eur/chf every 5 pips a new trade must be taken and want tp of 5 pips

 

not counting my chickens, but getting the idea

In my signature, there is a link to a website that shows my results on a demo account using a grid technique. Follow if you wish. I am not attempting to contradict (<-look that word up, beautiful origins) any opinions. Rather than speculate about currency pairs that run a huge range, let us test and be certain. The experiment will probably take a long time.

sn

 

well said, -- in different market condition, one of the strategy must prevail and probably not the stubborn pattern that you see in the last 5 hours

therefore, backtesting also miss out the volatility of the hot lava during 2 to 3 minutes period

i.e. only LIVE Trading, can give you a fair performance over a period

and -- if the market condition go against, you , can you STOP entries totally -- this is the key to success, rather than thinking of 365 days continuous trading or weekly period

danielfppps:
What you want to do is very hard. It is extremely difficult to use different trading techniques depending on market conditions. Most of the time the wisest approach to long term profits is to build a trend following system that stops loses quickly and lets profits run. Like most successful traders have advised for a few decades.

However, the approach you want to do with grid trading plus other techniques has been implemented in a few commercial experts, the most popular being pointbreak and the dreambuilder FX which use grid trading, pyramiding and averaging to tackle different faces of the market. Its approach is somewhat successful although draw downs are still pretty significant.

I hope you have good luck with your approach, you are free to use my newgrid code as you see fit.