• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • User/Email: Password:
  • 7:08am
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 7:08am
Sister Sites
  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

Stop Loss vs. Hidden Stop Loss 26 replies

Trailing stop loss code 2 replies

stop loss and take profit code 0 replies

Code adjustment for Trailing Stop Loss 2 replies

I need to add SL (Stop Loss) to this simple MACD EA 0 replies

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe
  • 2
Attachments: Stop Loss Code needed to add to this EA
Exit Attachments
Tags: Stop Loss Code needed to add to this EA
Cancel

Stop Loss Code needed to add to this EA

  • Post #1
  • Quote
  • First Post: Oct 7, 2009 11:15am Oct 7, 2009 11:15am
  •  gangsta1
  • | Commercial Member | Joined Jul 2009 | 159 Posts
Hi All,


I am attempting to backtest an EA, however in order to do so efficiently I need to add a stop loss sunction.
Can anyone please provide me with some code to add to my EA? I do have money management EA's, but I cannot run them simultaneously iwith my EA during backtesting.


Many Thanks,


Rich.


P.S. The EA code is at EA needs stop loss
  • Post #2
  • Quote
  • Edited 1:00pm Oct 7, 2009 11:23am | Edited 1:00pm
  •  skorcht
  • | Joined Jun 2006 | Status: Member | 173 Posts
#property copyright "Copyright 2008, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
extern double Lots = 0.1;
extern int ChasStart = 10;
extern int ChasStop = 22;
extern int Step = 15;
extern int TP = 200;
extern int StopLoss = 25;
int prevtime;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----


int OrderCountOtl=0;
int i=0;
int total = OrdersTotal();
for(i = 0; i <= total; i++)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderMagicNumber() == 12321)
{
if (OrderType()>1) OrderCountOtl++;
}
}
if (OrderCountOtl==1)
{
for(i = 0; i <= total; i++)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderMagicNumber() == 12321)
{
if (OrderType()>1) OrderDelete(OrderTicket());
}
}
}

if(Time[0] == prevtime)
return(0);
prevtime = Time[0];
if(!IsTradeAllowed())
{
prevtime = Time[1];
return(0);
}

if (TimeHour(TimeCurrent())==ChasStart && TimeMinute(TimeCurrent())==0)
{
OrderSend(Symbol(),OP_BUYSTOP,Lots, Ask+Step*Point,3,Ask-(StopLoss*Point),Ask+(Step +TP)*Point,"",12321,0,Green);
OrderSend(Symbol(),OP_SELLSTOP,Lots ,Bid-Step*Point,3,Bid+(StopLoss*Point),Bid-(Step+TP)*Point,"",12321,0,Red);
}
if (TimeHour(TimeCurrent())==ChasStop && TimeMinute(TimeCurrent())==0)
{
i=0;
total = OrdersTotal();
for(i = 0; i <= total; i++)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderMagicNumber() == 12321)
{
if (OrderType()==OP_BUY)OrderClose(OrderTicket(),OrderLots(),Bid,3,Green) ;
if (OrderType()==OP_SELL)OrderClose(OrderTicket(),OrderLots(),Ask,3,Green);
if (OrderType()>1)OrderDelete(OrderTicket());
}
}
}
//----
return(0);
}
taking series 3 and 34
 
 
  • Post #3
  • Quote
  • Oct 7, 2009 12:37pm Oct 7, 2009 12:37pm
  •  gangsta1
  • | Commercial Member | Joined Jul 2009 | 159 Posts
Thank You...

However I keep getting the good old OrderSend Error 130 even when I change the stop loss and take profit levels to amounts that would be valid..

Any suggestions please?
 
 
  • Post #4
  • Quote
  • Oct 7, 2009 12:52pm Oct 7, 2009 12:52pm
  •  skorcht
  • | Joined Jun 2006 | Status: Member | 173 Posts
Quoting gangsta1
Disliked
Thank You...

However I keep getting the good old OrderSend Error 130 even when I change the stop loss and take profit levels to amounts that would be valid..

Any suggestions please?
Ignored
HAHA..I should have drank coffee this morning before answering.
I fixed it above
taking series 3 and 34
 
 
  • Post #5
  • Quote
  • Oct 7, 2009 1:00pm Oct 7, 2009 1:00pm
  •  hayseed
  • Joined Nov 2006 | Status: Member | 3,637 Posts
hey rich..... this should do.......h
Attached File(s)
File Type: mq4 21hour.mq4   3 KB | 564 downloads
to trade and code, keep both simple... no call to impress....h
 
 
  • Post #6
  • Quote
  • Oct 7, 2009 1:32pm Oct 7, 2009 1:32pm
  •  gangsta1
  • | Commercial Member | Joined Jul 2009 | 159 Posts
Thank you guys, I will test them and let you know!
 
 
  • Post #7
  • Quote
  • Oct 8, 2009 6:11am Oct 8, 2009 6:11am
  •  gangsta1
  • | Commercial Member | Joined Jul 2009 | 159 Posts
work great, this EA is based on the Buyzone, however the results arent that great!
 
 
  • Post #8
  • Quote
  • Oct 8, 2009 7:53am Oct 8, 2009 7:53am
  •  hayseed
  • Joined Nov 2006 | Status: Member | 3,637 Posts
hey rich..... filter the trades with respect to the daily trend ...... allowing it to comply with the often despised nfa no-hedge rule and it's intended logic....

perhaps more important ...... as it stands now all trades are closed at the preset hour.... consider allowing winning trades to escape the closing hour's knife if it's profit is a certain amount .... the goal would be to accumulate winning trades allowing them to continue......

this will again bring big brother nfa in to the mix via fifo rule.... so the ea would have to be recoded to get around it......

changes such as those should improve preformance....... some other improvements come to mind..... h
to trade and code, keep both simple... no call to impress....h
 
 
  • Post #9
  • Quote
  • Oct 9, 2009 8:09am Oct 9, 2009 8:09am
  •  gangsta1
  • | Commercial Member | Joined Jul 2009 | 159 Posts
Thanks hayseed, do what you like with the code (I have no experience). If you make any progress let me know...

Cheers
 
 
  • Post #10
  • Quote
  • Oct 11, 2009 1:05pm Oct 11, 2009 1:05pm
  •  helloguy
  • | Joined Oct 2009 | Status: Junior Member | 10 Posts
Quoting hayseed
Disliked
this will again bring big brother nfa in to the mix via fifo rule.... so the ea would have to be recoded to get around it......
h
Ignored
Switch to the UK branch of your broker, or a broker that has a UK branch, then you don't have to worry about the stupid NFA anti hedging law.
 
 
  • Post #11
  • Quote
  • Last Post: Feb 9, 2017 12:35am Feb 9, 2017 12:35am
  •  abdool73
  • Joined Mar 2015 | Status: Member | 16 Posts
Quoting skorcht
Disliked
{quote} HAHA..I should have drank coffee this morning before answering. I fixed it above
Ignored
dear skorcht
plz add stoploss my ea
other u can make me same like ea with stop loss
Attached File(s)
File Type: mq4 Martingale 2312.mq4   8 KB | 320 downloads
 
 
  • Platform Tech
  • /
  • Stop Loss Code needed to add to this EA
  • Reply to Thread
0 traders viewing now
Top of Page
  • Facebook
  • Twitter
About FF
  • Mission
  • Products
  • User Guide
  • Media Kit
  • Blog
  • Contact
FF Products
  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer
FF Website
  • Homepage
  • Search
  • Members
  • Report a Bug
Follow FF
  • Facebook
  • Twitter

FF Sister Sites:

  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Forex Factory® is a brand of Fair Economy, Inc.

Terms of Service / ©2023