Would somebody please code my idea? SIMPLE!

Hello Babypips scene, i would like to ask someone who has some freetime to create my idea in EA.

Well, its really simple.

Martiangle system, which means as you know double the position size if the trader is loser.

Starting lotsize: 0,01

TP: 10pip without spread \ SL: 10pip without spread

If the trade gone lose, and the 10pip SL executed, the EA must open a new position with doubled position size in the opposite direction which was the loser’s direction. Example: We buy E\U, and our SL is executed. Next trade is opened with double lotsize sell E\U. If this is also loser, we open a new position to buy E\U with doubled lotsize. If its winner, we are happy.

If the first trade gone winner, the EA must open a new position in the same direction with the standard 10pip TP and 10pip SL.

It must open a new trade as the last trade executed. So i would like the EA to open positions all the day.

The first trade direction’s is random.

So, i would be really happy if somebody would code this. If something is not clear, please ask!

Thank you!

I may do it tomorrow if I have some time, but I don’t see this being profitable to be honest.

I’m not a good programmer, so make sure this works as expected :wink:


//+------------------------------------------------------------------+
//|                                                   Martiangle.mq4 |
//|                                           Copyright © 2010, Simy |
//|                     http://forums.babypips.com/members/simy.html |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, Simy"
#property link      "http://forums.babypips.com/members/simy.html"

//Vars
extern double Starting_Lots = 0.1;
extern double Stop_Loss = 200;
extern double Take_Profit = 200;
extern double Slippage = 0;
int magic = 12334;
int last_order = 0;


int Check_Open()
{
   for(int cnt=0;cnt<=OrdersTotal();cnt++)
   {
      OrderSelect(cnt, SELECT_BY_POS);
      if (OrderMagicNumber() == magic) return(OrderTicket());
      else
      {
         Print("No Open Order detected, Will attempt to open one");
         last_order = OrderSend(Symbol(),OP_SELL,Starting_Lots,Bid,Slippage,Bid+(Stop_Loss*Point),Bid-(Take_Profit*Point),"Martiangle",magic,0,Yellow);
         return(last_order);
      }
   }
}

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
{
   if (last_order == 0)
   {
      last_order=Check_Open();
      if (last_order <= 0)
      {
         Print("I cant seem to find or create a trade!");
         Print("OrderSend failed with error #",GetLastError());
         return(-1);
      }
   }
   
   if (OrderSelect(last_order, SELECT_BY_TICKET)!=true) 
   {
      Print("I can\'t select Order#",last_order," ! Error: ", GetLastError());
      return(-1);
   }
   
   if (OrderCloseTime() == 0) return(0);
   if (OrderProfit() <= 0)
   {
      double lots=OrderLots()+OrderLots();
      if (OrderType() == OP_BUY) last_order = OrderSend(Symbol(),OP_SELL,lots,Bid,Slippage,Bid+Stop_Loss*Point,Bid-Take_Profit*Point,"Martiangle",magic,0,Yellow);
      if (OrderType() == OP_SELL) last_order = OrderSend(Symbol(),OP_BUY,lots,Ask,Slippage,Ask-Stop_Loss*Point,Ask+Take_Profit*Point,"Martiangle",magic,0,Yellow);
      if (OrderType() != OP_SELL && OrderType() != OP_BUY) Print("I\'m confused and broken! I found an order type that I don\'t open!");
   }
   else
   {
      if (OrderType() == OP_SELL) last_order = OrderSend(Symbol(),OP_SELL,Starting_Lots,Bid,Slippage,Bid+Stop_Loss*Point,Bid-Take_Profit*Point,"Martiangle",magic,0,Yellow);
      if (OrderType() == OP_BUY) last_order = OrderSend(Symbol(),OP_BUY,Starting_Lots,Ask,Slippage,Ask-Stop_Loss*Point,Ask+Take_Profit*Point,"Martiangle",magic,0,Yellow);
      if (OrderType() != OP_SELL && OrderType() != OP_BUY) Print("I\'m confused and broken! I found an order type that I don\'t open!");
   }
   if (last_order <=0)
   {
      Print("OrderSend failed with error #",GetLastError());
      return(-10);

   }
   return(-3);
}
//+------------------------------------------------------------------+

Thank you man! Your work is great, but there are some expects :frowning:
-When the winner has occured after a few losses, then it must open a new trade with the [B]starting lotsize[/B] (0.01)in the [B]winner’s direction.[/B]
-It doesn’t work on other pairs. Don’t you know what can be the problem?

By the way, thank you! If you could fix these bugs that would be really great! :slight_smile:

Please show me or help me understand better what it is not doing. I’ve ran this on USD/JPY and EUR/USD. It goes broke quickly granted, but it fails both times. I’ve edited the code to only throw an error one time (because its only throwing it when it goes broke)

I wouldn’t live trade with this until a real programmer looks it over…
USD/JPY:

2010.09.07 13:10:36	1999.09.01 09:18  Martiangle USDJPY,M1: OrderSend failed with error #134
2010.09.07 13:10:36	1999.09.01 09:18  Martiangle USDJPY,M1: OrderSend error 134
2010.09.07 13:10:36	1999.09.01 09:18  Tester: PrevBalance: 31903.83, PrevPL: 0.00, PrevEquity 31903.83, PrevMargin: 0.00, NewMargin: 40960, FreeMargin: -9056.17
2010.09.07 13:10:36	1999.09.01 09:18  Tester: not enough money for buy 204.80 USDJPY at 109.410 sl: 109.310 tp: 109.610 [1999.09.01 09:18]
2010.09.07 13:10:36	1999.09.01 09:18  Tester: stop loss #24 at 109.380 (109.400 / 109.410)
2010.09.07 13:10:36	1999.09.01 09:16  Martiangle USDJPY,M1: open #24 sell 102.40 USDJPY at 109.280 sl: 109.380 tp: 109.080 ok
2010.09.07 13:10:36	1999.09.01 09:16  Tester: stop loss #23 at 109.280 (109.280 / 109.290)
2010.09.07 13:10:36	1999.09.01 09:14  Martiangle USDJPY,M1: open #23 buy 51.20 USDJPY at 109.380 sl: 109.280 tp: 109.580 ok
2010.09.07 13:10:36	1999.09.01 09:14  Tester: stop loss #22 at 109.380 (109.370 / 109.380)
2010.09.07 13:10:36	1999.09.01 08:40  Martiangle USDJPY,M1: open #22 sell 25.60 USDJPY at 109.280 sl: 109.380 tp: 109.080 ok
2010.09.07 13:10:36	1999.09.01 08:40  Tester: stop loss #21 at 109.310 (109.280 / 109.290)
2010.09.07 13:10:36	1999.09.01 08:40  Martiangle USDJPY,M1: open #21 buy 12.80 USDJPY at 109.410 sl: 109.310 tp: 109.610 ok
2010.09.07 13:10:36	1999.09.01 08:40  Tester: stop loss #20 at 109.370 (109.400 / 109.410)
2010.09.07 13:10:36	1999.09.01 08:23  Martiangle USDJPY,M1: open #20 sell 6.40 USDJPY at 109.270 sl: 109.370 tp: 109.070 ok
2010.09.07 13:10:36	1999.09.01 08:23  Tester: stop loss #19 at 109.301 (109.270 / 109.280)
2010.09.07 13:10:36	1999.09.01 08:14  Martiangle USDJPY,M1: open #19 buy 3.20 USDJPY at 109.401 sl: 109.301 tp: 109.601 ok
2010.09.07 13:10:36	1999.09.01 08:14  Tester: stop loss #18 at 109.400 (109.391 / 109.401)
2010.09.07 13:10:36	1999.09.01 08:14  Martiangle USDJPY,M1: open #18 sell 1.60 USDJPY at 109.300 sl: 109.400 tp: 109.100 ok
2010.09.07 13:10:36	1999.09.01 08:14  Tester: stop loss #17 at 109.357 (109.300 / 109.310)
2010.09.07 13:10:36	1999.09.01 08:13  Martiangle USDJPY,M1: open #17 buy 0.80 USDJPY at 109.457 sl: 109.357 tp: 109.657 ok
2010.09.07 13:10:36	1999.09.01 08:13  Tester: stop loss #16 at 109.386 (109.447 / 109.457)
2010.09.07 13:10:36	1999.09.01 08:06  Martiangle USDJPY,M1: open #16 sell 0.40 USDJPY at 109.286 sl: 109.386 tp: 109.086 ok
2010.09.07 13:10:36	1999.09.01 08:06  Tester: stop loss #15 at 109.289 (109.286 / 109.296)
2010.09.07 13:10:36	1999.09.01 08:05  Martiangle USDJPY,M1: open #15 buy 0.20 USDJPY at 109.389 sl: 109.289 tp: 109.589 ok
2010.09.07 13:10:36	1999.09.01 08:05  Tester: stop loss #14 at 109.370 (109.379 / 109.389)
2010.09.07 13:10:36	1999.09.01 08:05  Martiangle USDJPY,M1: open #14 sell 0.10 USDJPY at 109.270 sl: 109.370 tp: 109.070 ok
2010.09.07 13:10:36	1999.09.01 08:05  Tester: take profit #13 at 109.290 (109.270 / 109.280)
2010.09.07 13:10:36	1999.09.01 07:24  Martiangle USDJPY,M1: open #13 sell 3.20 USDJPY at 109.490 sl: 109.590 tp: 109.290 ok
2010.09.07 13:10:36	1999.09.01 07:24  Tester: stop loss #12 at 109.500 (109.490 / 109.500)
2010.09.07 13:10:36	1999.09.01 07:24  Martiangle USDJPY,M1: open #12 buy 1.60 USDJPY at 109.600 sl: 109.500 tp: 109.800 ok
2010.09.07 13:10:36	1999.09.01 07:24  Tester: stop loss #11 at 109.570 (109.590 / 109.600)
2010.09.07 13:10:36	1999.09.01 07:09  Martiangle USDJPY,M1: open #11 sell 0.80 USDJPY at 109.470 sl: 109.570 tp: 109.270 ok
2010.09.07 13:10:36	1999.09.01 07:09  Tester: stop loss #10 at 109.470 (109.470 / 109.480)
2010.09.07 13:10:36	1999.09.01 07:05  Martiangle USDJPY,M1: open #10 buy 0.40 USDJPY at 109.570 sl: 109.470 tp: 109.770 ok
2010.09.07 13:10:36	1999.09.01 07:05  Tester: stop loss #9 at 109.570 (109.560 / 109.570)
2010.09.07 13:10:36	1999.09.01 05:51  Martiangle USDJPY,M1: open #9 sell 0.20 USDJPY at 109.470 sl: 109.570 tp: 109.270 ok
2010.09.07 13:10:36	1999.09.01 05:51  Tester: stop loss #8 at 109.522 (109.470 / 109.480)
2010.09.07 13:10:36	1999.09.01 05:38  Martiangle USDJPY,M1: open #8 buy 0.10 USDJPY at 109.622 sl: 109.522 tp: 109.822 ok
2010.09.07 13:10:36	1999.09.01 05:38  Tester: take profit #7 at 109.600 (109.612 / 109.622)
2010.09.07 13:10:36	1999.09.01 04:27  Martiangle USDJPY,M1: open #7 buy 3.20 USDJPY at 109.400 sl: 109.300 tp: 109.600 ok
2010.09.07 13:10:36	1999.09.01 04:27  Tester: stop loss #6 at 109.397 (109.390 / 109.400)
2010.09.07 13:10:36	1999.09.01 04:19  Martiangle USDJPY,M1: open #6 sell 1.60 USDJPY at 109.297 sl: 109.397 tp: 109.097 ok
2010.09.07 13:10:36	1999.09.01 04:19  Tester: stop loss #5 at 109.305 (109.297 / 109.307)
2010.09.07 13:10:36	1999.09.01 04:11  Martiangle USDJPY,M1: open #5 buy 0.80 USDJPY at 109.405 sl: 109.305 tp: 109.605 ok
2010.09.07 13:10:36	1999.09.01 04:11  Tester: stop loss #4 at 109.400 (109.395 / 109.405)
2010.09.07 13:10:36	1999.09.01 04:08  Martiangle USDJPY,M1: open #4 sell 0.40 USDJPY at 109.300 sl: 109.400 tp: 109.100 ok
2010.09.07 13:10:36	1999.09.01 04:08  Tester: stop loss #3 at 109.310 (109.300 / 109.310)
2010.09.07 13:10:36	1999.09.01 03:06  Martiangle USDJPY,M1: open #3 buy 0.20 USDJPY at 109.410 sl: 109.310 tp: 109.610 ok
2010.09.07 13:10:36	1999.09.01 03:06  Tester: stop loss #2 at 109.400 (109.400 / 109.410)
2010.09.07 13:10:36	1999.09.01 03:05  Martiangle USDJPY,M1: open #2 sell 0.10 USDJPY at 109.300 sl: 109.400 tp: 109.100 ok
2010.09.07 13:10:36	1999.09.01 03:05  Tester: take profit #1 at 109.320 (109.300 / 109.310)
2010.09.07 13:10:36	1999.09.01 02:55  Martiangle USDJPY,M1: open #1 sell 0.10 USDJPY at 109.520 sl: 109.620 tp: 109.320 ok
2010.09.07 13:10:36	1999.09.01 02:55  Martiangle USDJPY,M1: No Open Order detected, Will attempt to open one
2010.09.07 13:10:36	Martiangle inputs: Starting_Lots=0.1; Stop_Loss=100; Take_Profit=200; Slippage=0; 


EUR/USD:


2010.09.07 13:24:51	1999.10.04 01:57  Martiangle EURUSD,M1: OrderSend failed with error #134
2010.09.07 13:24:51	1999.10.04 01:57  Martiangle EURUSD,M1: OrderSend error 134
2010.09.07 13:24:51	1999.10.04 01:57  Tester: PrevBalance: 41563.52, PrevPL: 0.00, PrevEquity 41563.52, PrevMargin: 0.00, NewMargin: 43870, FreeMargin: -2306.28
2010.09.07 13:24:51	1999.10.04 01:57  Tester: not enough money for sell 204.80 EURUSD at 1.07100 sl: 1.07200 tp: 1.06900 [1999.10.04 01:57]
2010.09.07 13:24:51	1999.10.04 01:57  Tester: stop loss #56 at 1.07148 (1.07100 / 1.07108)
2010.09.07 13:24:51	1999.10.04 00:53  Martiangle EURUSD,M1: open #56 buy 102.40 EURUSD at 1.07248 sl: 1.07148 tp: 1.07448 ok
2010.09.07 13:24:51	1999.10.04 00:53  Tester: stop loss #55 at 1.07240 (1.07240 / 1.07248)
2010.09.07 13:24:51	1999.10.04 00:01  Martiangle EURUSD,M1: open #55 sell 51.20 EURUSD at 1.07140 sl: 1.07240 tp: 1.06940 ok
2010.09.07 13:24:51	1999.10.04 00:01  Tester: stop loss #54 at 1.07278 (1.07140 / 1.07148)
2010.09.07 13:24:51	1999.10.01 19:55  Martiangle EURUSD,M1: open #54 buy 25.60 EURUSD at 1.07378 sl: 1.07278 tp: 1.07578 ok
2010.09.07 13:24:51	1999.10.01 19:55  Tester: stop loss #53 at 1.07350 (1.07370 / 1.07378)
2010.09.07 13:24:51	1999.10.01 19:50  Martiangle EURUSD,M1: open #53 sell 12.80 EURUSD at 1.07250 sl: 1.07350 tp: 1.07050 ok
2010.09.07 13:24:51	1999.10.01 19:50  Tester: stop loss #52 at 1.07298 (1.07250 / 1.07258)
2010.09.07 13:24:51	1999.10.01 19:50  Martiangle EURUSD,M1: open #52 buy 6.40 EURUSD at 1.07398 sl: 1.07298 tp: 1.07598 ok
2010.09.07 13:24:51	1999.10.01 19:50  Tester: stop loss #51 at 1.07328 (1.07390 / 1.07398)
2010.09.07 13:24:51	1999.10.01 19:40  Martiangle EURUSD,M1: open #51 sell 3.20 EURUSD at 1.07228 sl: 1.07328 tp: 1.07028 ok
2010.09.07 13:24:51	1999.10.01 19:40  Tester: stop loss #50 at 1.07238 (1.07228 / 1.07236)
2010.09.07 13:24:51	1999.10.01 19:40  Martiangle EURUSD,M1: open #50 buy 1.60 EURUSD at 1.07338 sl: 1.07238 tp: 1.07538 ok
2010.09.07 13:24:51	1999.10.01 19:40  Tester: stop loss #49 at 1.07330 (1.07330 / 1.07338)
2010.09.07 13:24:51	1999.10.01 19:16  Martiangle EURUSD,M1: open #49 sell 0.80 EURUSD at 1.07230 sl: 1.07330 tp: 1.07030 ok
2010.09.07 13:24:51	1999.10.01 19:16  Tester: stop loss #48 at 1.07238 (1.07230 / 1.07238)
2010.09.07 13:24:51	1999.10.01 19:01  Martiangle EURUSD,M1: open #48 buy 0.40 EURUSD at 1.07338 sl: 1.07238 tp: 1.07538 ok
2010.09.07 13:24:51	1999.10.01 19:01  Tester: stop loss #47 at 1.07330 (1.07330 / 1.07338)
2010.09.07 13:24:51	1999.10.01 18:38  Martiangle EURUSD,M1: open #47 sell 0.20 EURUSD at 1.07230 sl: 1.07330 tp: 1.07030 ok
2010.09.07 13:24:51	1999.10.01 18:38  Tester: stop loss #46 at 1.07248 (1.07230 / 1.07238)
2010.09.07 13:24:51	1999.10.01 18:29  Martiangle EURUSD,M1: open #46 buy 0.10 EURUSD at 1.07348 sl: 1.07248 tp: 1.07548 ok
2010.09.07 13:24:51	1999.10.01 18:29  Tester: take profit #45 at 1.07291 (1.07340 / 1.07348)
2010.09.07 13:24:51	1999.10.01 17:13  Martiangle EURUSD,M1: open #45 buy 3.20 EURUSD at 1.07091 sl: 1.06991 tp: 1.07291 ok
2010.09.07 13:24:51	1999.10.01 17:13  Tester: stop loss #44 at 1.07085 (1.07083 / 1.07091)
2010.09.07 13:24:51	1999.10.01 17:07  Martiangle EURUSD,M1: open #44 sell 1.60 EURUSD at 1.06985 sl: 1.07085 tp: 1.06785 ok
2010.09.07 13:24:51	1999.10.01 17:07  Tester: stop loss #43 at 1.06991 (1.06985 / 1.06993)
2010.09.07 13:24:51	1999.10.01 17:04  Martiangle EURUSD,M1: open #43 buy 0.80 EURUSD at 1.07091 sl: 1.06991 tp: 1.07291 ok
2010.09.07 13:24:51	1999.10.01 17:04  Tester: stop loss #42 at 1.07090 (1.07083 / 1.07091)
2010.09.07 13:24:51	1999.10.01 16:58  Martiangle EURUSD,M1: open #42 sell 0.40 EURUSD at 1.06990 sl: 1.07090 tp: 1.06790 ok
2010.09.07 13:24:51	1999.10.01 16:58  Tester: stop loss #41 at 1.07008 (1.06990 / 1.06998)
2010.09.07 13:24:51	1999.10.01 16:20  Martiangle EURUSD,M1: open #41 buy 0.20 EURUSD at 1.07108 sl: 1.07008 tp: 1.07308 ok
2010.09.07 13:24:51	1999.10.01 16:20  Tester: stop loss #40 at 1.07100 (1.07100 / 1.07108)
2010.09.07 13:24:51	1999.10.01 16:17  Martiangle EURUSD,M1: open #40 sell 0.10 EURUSD at 1.07000 sl: 1.07100 tp: 1.06800 ok
2010.09.07 13:24:51	1999.10.01 16:17  Tester: take profit #39 at 1.07039 (1.07000 / 1.07008)
2010.09.07 13:24:51	1999.10.01 16:08  Martiangle EURUSD,M1: open #39 sell 1.60 EURUSD at 1.07239 sl: 1.07339 tp: 1.07039 ok
2010.09.07 13:24:51	1999.10.01 16:08  Tester: stop loss #38 at 1.07278 (1.07239 / 1.07247)
2010.09.07 13:24:51	1999.10.01 16:06  Martiangle EURUSD,M1: open #38 buy 0.80 EURUSD at 1.07378 sl: 1.07278 tp: 1.07578 ok
2010.09.07 13:24:51	1999.10.01 16:06  Tester: stop loss #37 at 1.07360 (1.07370 / 1.07378)
2010.09.07 13:24:51	1999.10.01 16:05  Martiangle EURUSD,M1: open #37 sell 0.40 EURUSD at 1.07260 sl: 1.07360 tp: 1.07060 ok
2010.09.07 13:24:51	1999.10.01 16:05  Tester: stop loss #36 at 1.07288 (1.07260 / 1.07268)
2010.09.07 13:24:51	1999.10.01 16:03  Martiangle EURUSD,M1: open #36 buy 0.20 EURUSD at 1.07388 sl: 1.07288 tp: 1.07588 ok
2010.09.07 13:24:51	1999.10.01 16:03  Tester: stop loss #35 at 1.07360 (1.07380 / 1.07388)
2010.09.07 13:24:51	1999.10.01 15:53  Martiangle EURUSD,M1: open #35 sell 0.10 EURUSD at 1.07260 sl: 1.07360 tp: 1.07060 ok
2010.09.07 13:24:51	1999.10.01 15:53  Tester: take profit #34 at 1.07270 (1.07260 / 1.07268)
2010.09.07 13:24:51	1999.10.01 15:28  Martiangle EURUSD,M1: open #34 sell 3.20 EURUSD at 1.07470 sl: 1.07570 tp: 1.07270 ok
2010.09.07 13:24:51	1999.10.01 15:28  Tester: stop loss #33 at 1.07478 (1.07470 / 1.07478)
2010.09.07 13:24:51	1999.10.01 15:26  Martiangle EURUSD,M1: open #33 buy 1.60 EURUSD at 1.07578 sl: 1.07478 tp: 1.07778 ok
2010.09.07 13:24:51	1999.10.01 15:26  Tester: stop loss #32 at 1.07570 (1.07570 / 1.07578)
2010.09.07 13:24:51	1999.10.01 15:22  Martiangle EURUSD,M1: open #32 sell 0.80 EURUSD at 1.07470 sl: 1.07570 tp: 1.07270 ok
2010.09.07 13:24:51	1999.10.01 15:22  Tester: stop loss #31 at 1.07478 (1.07470 / 1.07478)
2010.09.07 13:24:51	1999.10.01 15:14  Martiangle EURUSD,M1: open #31 buy 0.40 EURUSD at 1.07578 sl: 1.07478 tp: 1.07778 ok
2010.09.07 13:24:51	1999.10.01 15:14  Tester: stop loss #30 at 1.07570 (1.07570 / 1.07578)
2010.09.07 13:24:51	1999.10.01 15:04  Martiangle EURUSD,M1: open #30 sell 0.20 EURUSD at 1.07470 sl: 1.07570 tp: 1.07270 ok
2010.09.07 13:24:51	1999.10.01 15:04  Tester: stop loss #29 at 1.07478 (1.07470 / 1.07478)
2010.09.07 13:24:51	1999.10.01 14:56  Martiangle EURUSD,M1: open #29 buy 0.10 EURUSD at 1.07578 sl: 1.07478 tp: 1.07778 ok
2010.09.07 13:24:51	1999.10.01 14:56  Tester: take profit #28 at 1.07560 (1.07570 / 1.07578)
2010.09.07 13:24:51	1999.10.01 14:33  Martiangle EURUSD,M1: open #28 buy 12.80 EURUSD at 1.07360 sl: 1.07260 tp: 1.07560 ok
2010.09.07 13:24:51	1999.10.01 14:33  Tester: stop loss #27 at 1.07360 (1.07352 / 1.07360)
2010.09.07 13:24:51	1999.10.01 14:15  Martiangle EURUSD,M1: open #27 sell 6.40 EURUSD at 1.07260 sl: 1.07360 tp: 1.07060 ok
2010.09.07 13:24:51	1999.10.01 14:15  Tester: stop loss #26 at 1.07268 (1.07260 / 1.07268)
2010.09.07 13:24:51	1999.10.01 14:07  Martiangle EURUSD,M1: open #26 buy 3.20 EURUSD at 1.07368 sl: 1.07268 tp: 1.07568 ok
2010.09.07 13:24:51	1999.10.01 14:07  Tester: stop loss #25 at 1.07360 (1.07360 / 1.07368)
2010.09.07 13:24:51	1999.10.01 13:06  Martiangle EURUSD,M1: open #25 sell 1.60 EURUSD at 1.07260 sl: 1.07360 tp: 1.07060 ok
2010.09.07 13:24:51	1999.10.01 13:06  Tester: stop loss #24 at 1.07268 (1.07260 / 1.07268)
2010.09.07 13:24:51	1999.10.01 12:40  Martiangle EURUSD,M1: open #24 buy 0.80 EURUSD at 1.07368 sl: 1.07268 tp: 1.07568 ok
2010.09.07 13:24:51	1999.10.01 12:40  Tester: stop loss #23 at 1.07367 (1.07360 / 1.07368)
2010.09.07 13:24:51	1999.10.01 12:28  Martiangle EURUSD,M1: open #23 sell 0.40 EURUSD at 1.07267 sl: 1.07367 tp: 1.07067 ok
2010.09.07 13:24:51	1999.10.01 12:28  Tester: stop loss #22 at 1.07288 (1.07267 / 1.07275)
2010.09.07 13:24:51	1999.10.01 12:25  Martiangle EURUSD,M1: open #22 buy 0.20 EURUSD at 1.07388 sl: 1.07288 tp: 1.07588 ok
2010.09.07 13:24:51	1999.10.01 12:25  Tester: stop loss #21 at 1.07380 (1.07380 / 1.07388)
2010.09.07 13:24:51	1999.10.01 12:06  Martiangle EURUSD,M1: open #21 sell 0.10 EURUSD at 1.07280 sl: 1.07380 tp: 1.07080 ok
2010.09.07 13:24:51	1999.10.01 12:06  Tester: take profit #20 at 1.07290 (1.07280 / 1.07288)
2010.09.07 13:24:51	1999.10.01 10:55  Martiangle EURUSD,M1: open #20 sell 3.20 EURUSD at 1.07490 sl: 1.07590 tp: 1.07290 ok
2010.09.07 13:24:51	1999.10.01 10:55  Tester: stop loss #19 at 1.07508 (1.07490 / 1.07498)
2010.09.07 13:24:51	1999.10.01 10:52  Martiangle EURUSD,M1: open #19 buy 1.60 EURUSD at 1.07608 sl: 1.07508 tp: 1.07808 ok
2010.09.07 13:24:51	1999.10.01 10:52  Tester: stop loss #18 at 1.07606 (1.07600 / 1.07608)
2010.09.07 13:24:51	1999.10.01 10:46  Martiangle EURUSD,M1: open #18 sell 0.80 EURUSD at 1.07506 sl: 1.07606 tp: 1.07306 ok
2010.09.07 13:24:51	1999.10.01 10:46  Tester: stop loss #17 at 1.07513 (1.07506 / 1.07514)
2010.09.07 13:24:51	1999.10.01 10:36  Martiangle EURUSD,M1: open #17 buy 0.40 EURUSD at 1.07613 sl: 1.07513 tp: 1.07813 ok
2010.09.07 13:24:51	1999.10.01 10:36  Tester: stop loss #16 at 1.07610 (1.07605 / 1.07613)
2010.09.07 13:24:51	1999.10.01 10:36  Martiangle EURUSD,M1: open #16 sell 0.20 EURUSD at 1.07510 sl: 1.07610 tp: 1.07310 ok
2010.09.07 13:24:51	1999.10.01 10:36  Tester: stop loss #15 at 1.07513 (1.07510 / 1.07518)
2010.09.07 13:24:51	1999.10.01 10:35  Martiangle EURUSD,M1: open #15 buy 0.10 EURUSD at 1.07613 sl: 1.07513 tp: 1.07813 ok
2010.09.07 13:24:51	1999.10.01 10:35  Tester: take profit #14 at 1.07578 (1.07605 / 1.07613)
2010.09.07 13:24:51	1999.10.01 10:27  Martiangle EURUSD,M1: open #14 buy 0.10 EURUSD at 1.07378 sl: 1.07278 tp: 1.07578 ok
2010.09.07 13:24:51	1999.10.01 10:27  Tester: take profit #13 at 1.07314 (1.07370 / 1.07378)
2010.09.07 13:24:51	1999.10.01 10:15  Martiangle EURUSD,M1: open #13 buy 102.40 EURUSD at 1.07114 sl: 1.07014 tp: 1.07314 ok
2010.09.07 13:24:51	1999.10.01 10:15  Tester: stop loss #12 at 1.07100 (1.07106 / 1.07114)
2010.09.07 13:24:51	1999.10.01 10:05  Martiangle EURUSD,M1: open #12 sell 51.20 EURUSD at 1.07000 sl: 1.07100 tp: 1.06800 ok
2010.09.07 13:24:51	1999.10.01 10:05  Tester: stop loss #11 at 1.07028 (1.07000 / 1.07008)
2010.09.07 13:24:51	1999.10.01 09:57  Martiangle EURUSD,M1: open #11 buy 25.60 EURUSD at 1.07128 sl: 1.07028 tp: 1.07328 ok
2010.09.07 13:24:51	1999.10.01 09:57  Tester: stop loss #10 at 1.07120 (1.07120 / 1.07128)
2010.09.07 13:24:51	1999.10.01 09:49  Martiangle EURUSD,M1: open #10 sell 12.80 EURUSD at 1.07020 sl: 1.07120 tp: 1.06820 ok
2010.09.07 13:24:51	1999.10.01 09:49  Tester: stop loss #9 at 1.07043 (1.07020 / 1.07028)
2010.09.07 13:24:51	1999.10.01 09:43  Martiangle EURUSD,M1: open #9 buy 6.40 EURUSD at 1.07143 sl: 1.07043 tp: 1.07343 ok
2010.09.07 13:24:51	1999.10.01 09:43  Tester: stop loss #8 at 1.07140 (1.07135 / 1.07143)
2010.09.07 13:24:51	1999.10.01 09:36  Martiangle EURUSD,M1: open #8 sell 3.20 EURUSD at 1.07040 sl: 1.07140 tp: 1.06840 ok
2010.09.07 13:24:51	1999.10.01 09:36  Tester: stop loss #7 at 1.07048 (1.07040 / 1.07048)
2010.09.07 13:24:51	1999.10.01 09:32  Martiangle EURUSD,M1: open #7 buy 1.60 EURUSD at 1.07148 sl: 1.07048 tp: 1.07348 ok
2010.09.07 13:24:51	1999.10.01 09:32  Tester: stop loss #6 at 1.07140 (1.07140 / 1.07148)
2010.09.07 13:24:51	1999.10.01 09:29  Martiangle EURUSD,M1: open #6 sell 0.80 EURUSD at 1.07040 sl: 1.07140 tp: 1.06840 ok
2010.09.07 13:24:51	1999.10.01 09:29  Tester: stop loss #5 at 1.07048 (1.07040 / 1.07048)
2010.09.07 13:24:51	1999.10.01 09:18  Martiangle EURUSD,M1: open #5 buy 0.40 EURUSD at 1.07148 sl: 1.07048 tp: 1.07348 ok
2010.09.07 13:24:51	1999.10.01 09:18  Tester: stop loss #4 at 1.07130 (1.07140 / 1.07148)
2010.09.07 13:24:51	1999.10.01 08:15  Martiangle EURUSD,M1: open #4 sell 0.20 EURUSD at 1.07030 sl: 1.07130 tp: 1.06830 ok
2010.09.07 13:24:51	1999.10.01 08:15  Tester: stop loss #3 at 1.07048 (1.07030 / 1.07038)
2010.09.07 13:24:51	1999.10.01 04:49  Martiangle EURUSD,M1: open #3 buy 0.10 EURUSD at 1.07148 sl: 1.07048 tp: 1.07348 ok
2010.09.07 13:24:51	1999.10.01 04:49  Tester: take profit #2 at 1.07138 (1.07140 / 1.07148)
2010.09.07 13:24:51	1999.10.01 04:16  Martiangle EURUSD,M1: open #2 buy 0.20 EURUSD at 1.06938 sl: 1.06838 tp: 1.07138 ok
2010.09.07 13:24:51	1999.10.01 04:16  Tester: stop loss #1 at 1.06920 (1.06930 / 1.06938)
2010.09.07 13:24:51	1999.10.01 03:17  Martiangle EURUSD,M1: open #1 sell 0.10 EURUSD at 1.06820 sl: 1.06920 tp: 1.06620 ok
2010.09.07 13:24:50	1999.10.01 03:17  Martiangle EURUSD,M1: No Open Order detected, Will attempt to open one
2010.09.07 13:24:50	Martiangle inputs: Starting_Lots=0.1; Stop_Loss=100; Take_Profit=200; Slippage=0; 


Newest code:


//+------------------------------------------------------------------+
//|                                                   Martiangle.mq4 |
//|                                           Copyright © 2010, Simy |
//|                     http://forums.babypips.com/members/simy.html |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, Simy"
#property link      "http://forums.babypips.com/members/simy.html"

//Vars
extern double Starting_Lots = 0.1;
extern double Stop_Loss = 100;
extern double Take_Profit = 200;
extern double Slippage = 0;
int magic = 12334;
int last_order = 0;
bool fail_once = false;

int Check_Open()
{
   for(int cnt=0;cnt<=OrdersTotal();cnt++)
   {
      OrderSelect(cnt, SELECT_BY_POS);
      if (OrderMagicNumber() == magic) return(OrderTicket());
      else
      {
         Print("No Open Order detected, Will attempt to open one");
         last_order = OrderSend(Symbol(),OP_SELL,Starting_Lots,Bid,Slippage,Bid+(Stop_Loss*Point),Bid-(Take_Profit*Point),"Martiangle",magic,0,Yellow);
         return(last_order);
      }
   }
}

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
{
   if (last_order == 0)
   {
      last_order=Check_Open();
      if (last_order <= 0)
      {
         Print("I cant seem to find or create a trade!");
         Print("OrderSend failed with error #",GetLastError());
         return(-1);
      }
   }
   
   if (OrderSelect(last_order, SELECT_BY_TICKET)!=true) 
   {
      if (fail_once) 
      {
         Print("I can\'t select Order#",last_order," ! Error: ", GetLastError());
         fail_once = true;
      }
      return(-1);
   }
   
   if (OrderCloseTime() == 0) return(0);
   if (OrderProfit() <= 0)
   {
      double lots=OrderLots()+OrderLots();
      if (OrderType() == OP_BUY) last_order = OrderSend(Symbol(),OP_SELL,lots,Bid,Slippage,Bid+Stop_Loss*Point,Bid-Take_Profit*Point,"Martiangle",magic,0,Yellow);
      if (OrderType() == OP_SELL) last_order = OrderSend(Symbol(),OP_BUY,lots,Ask,Slippage,Ask-Stop_Loss*Point,Ask+Take_Profit*Point,"Martiangle",magic,0,Yellow);
      if (OrderType() != OP_SELL && OrderType() != OP_BUY) Print("I\'m confused and broken! I found an order type that I don\'t open!");
   }
   else
   {
      if (OrderType() == OP_SELL) last_order = OrderSend(Symbol(),OP_SELL,Starting_Lots,Bid,Slippage,Bid+Stop_Loss*Point,Bid-Take_Profit*Point,"Martiangle",magic,0,Yellow);
      if (OrderType() == OP_BUY) last_order = OrderSend(Symbol(),OP_BUY,Starting_Lots,Ask,Slippage,Ask-Stop_Loss*Point,Ask+Take_Profit*Point,"Martiangle",magic,0,Yellow);
      if (OrderType() != OP_SELL && OrderType() != OP_BUY) Print("I\'m confused and broken! I found an order type that I don\'t open!");
   }
   if (last_order <=0)
   {
      Print("OrderSend failed with error #",GetLastError());
      return(-10);

   }
   return(-3);
}
//+------------------------------------------------------------------+

Would someone please upload this script in the EX4 file. Thanks in advance.

[QUOTE=antonioforex;218569]Would someone please upload this script in the EX4 file. Thanks in advance.[/QUOTE]

Here you go.

I slightly modified, first it creates order and then modify order with SL & TP. This way it work on my broker account.

Thank you.

Sounds a bit dangerous that way.

Knowing my luck after the order is sent, but before the modify is taken place thats when I would have an IPC issue.

What broker do you have?

My broker is IamFX

I don’t know why this happens but after it runs for a while it just stops and it doesn’t open any more trades.

Also I have a few questions:

  1. Is it possible to alter it so you can turn the martingale ON/OFF.

  2. Can you limit the martingale sequence? For instance you want the martingale to double 3 times and then start over.

  3. And finally, let’s say we enter a [B]long[/B] position, can we have a buy order set in place in case we win and a sell order in place we lose. Whatever happens the previous[B] long[/B] position should be closed. That way if there is a quick move in price our position will be triggered. Also once one position is triggered the other should be cancelled.

Hope that makes sense and someone can adjust this. Thank you very much!

Antonio

everest07, Thanks for that info.

antonioforex,
Its most likely stopping because your back test account went broke, but what do the logs say?

As far as modifying it that sounds quite reasonable to do, however It’s outside the scope of what I’m able to commit to at the moment. Currently I’m writing several function calls to be able to backtest my own strategies; If after that there are no takers, I may code in those options.

Simy,

Account is actually in profit and the logs aren’t saying anything that would explain it. Thanks.

Antonio

Any other programmer interested in taking a crack at this?