GET_LUCKY_(Modified)_v102_SL

Author: Copyright � 2008, Pierre Mouawad
Orders Execution
Checks for the total of open ordersIt can change open orders parameters, due to possible stepping strategyIt automatically opens orders when conditions are reached
Indicators Used
DeMarker indicatorParabolic Stop and Reverse systemIndicator of the average true range
0 Views
0 Downloads
0 Favorites

Profitability Reports

AUD/USD Oct 2024 - Jan 2025
8.00 %
Total Trades 4
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -2301.35
Gross Profit 750.00
Gross Loss -9955.40
Total Net Profit -9205.40
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
8.00 %
Total Trades 4
Won Trades 1
Lost trades 3
Win Rate 0.25 %
Expected payoff -2074.34
Gross Profit 750.00
Gross Loss -9047.35
Total Net Profit -8297.35
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
35.00 %
Total Trades 5
Won Trades 2
Lost trades 3
Win Rate 0.40 %
Expected payoff -580.50
Gross Profit 1562.50
Gross Loss -4464.99
Total Net Profit -2902.49
-100%
-50%
0%
50%
100%
GET_LUCKY_(Modified)_v102_SL
//+------------------------------------------------------------------+
//|                                                    GET LUCKY.mq4 |
//|                                 Copyright © 2009, Pierre Mouawad |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Pierre Mouawad"

//---- input parameters
extern int       DemPeriod  = 12;
extern double    DemLevel1  = 0.3;
extern double    DemLevel2  = 0.7;
extern double    Step       = 0.003;
extern double    Max        = 0.2;
extern int       TakeProfit = 125;
extern int       StopLoss   =0;
extern int       InitStopLoss   =0;
extern int TrailingStep=0;//|--------------------trailing step
extern bool UseATRTS=false;//|--------------------trailing stop based on average true range
extern int ATRTSTimeFrame=0;//|-------------------average true range time frame
extern int ATRTSPeriod=14;//|---------------------average true range period
extern double ATRTSFactor=1;//|-------------------average true range factor
extern double    Perc       = 3;     //--- Percentage of Account to invest
extern double    Lots       = 1;     //--- If Perc=0, Lots is Fixed to this amount
extern double    Mult       = 2;
extern int       MaxTrades  = 4;     //--- Maximum Number of Trades to Open
extern int       Level      = 70;    //--- the level where the EA starts averaging
extern int       Slippage   = 10;
extern int       LotC       = 500;   //--- Lot Cost (based on margin requirement and type of account
extern int Magic=2009;
int    TradeType=0, TradeCount=0;
double Lotsi=0, TradePrice=0, NewTarget=0, NewStop=0, AverageLong=0, AverageShort=0;
double x=0;

//+------------------------------------------------------------------+
int digits,multi;
double point;
double SL,SL1;
int init()
{
   digits=Digits;
   if(Digits==3 || Digits==5){point=Point*10;multi=10;}else{point=Point;multi=1;}
}

int start()
   {//|---------trailing stop
   if(UseATRTS)MoveATRTS();
   
   double H, Hi, L, Lo, Cl, Clo1, Clo2, dm, sar, sar1, sar2;
  
   H    = High[0];
   Hi   = High[1];
   L    = Low[0];
   Lo   = Low[1];
   Cl   = Close[0];
   Clo1 = Close[1];
   Clo2 = Close[2];
   
   dm    = iDeMarker(NULL, 0, DemPeriod, 0);
   
   sar   = iSAR(NULL, 0, Step, Max, 0);
   sar1  = iSAR(NULL, 0, Step, Max, 1);
   sar2  = iSAR(NULL, 0, Step, Max, 2);

//-- check for open orders and their details
   int Total=OrdersTotal();
   if(TradeCount==MaxTrades && Total==0) TradeCount=0;
   for(int cnt=0; cnt<Total; cnt++)
      {
      OrderSelect(cnt, SELECT_BY_POS);
      if(OrderSymbol()==Symbol() && OrderType()==OP_BUY && OrderMagicNumber() == Magic)
         {
         TradeType=1;
         TradeCount++;
         TradePrice    = OrderOpenPrice();
         NewTarget     = OrderTakeProfit();
         NewStop       = OrderStopLoss();
         Lotsi         = OrderLots();
       
         if(TradeCount>1)
            {
            OrderSelect(cnt-1, SELECT_BY_POS);
            if(OrderTakeProfit() != NewTarget  )
            OrderModify(OrderTicket(),OrderOpenPrice(),NewStop,NewTarget,0);
            }
         }
      if(OrderSymbol()==Symbol() && OrderType()==OP_SELL && OrderMagicNumber() == Magic)
         {
         TradeType=2;
         TradeCount++;
         TradePrice    = OrderOpenPrice();
         NewTarget     = OrderTakeProfit();
         NewStop       = OrderStopLoss();
         Lotsi         = OrderLots();
         
         if(TradeCount>1)
            {
            OrderSelect(cnt-1, SELECT_BY_POS);
            if(OrderTakeProfit() != NewTarget  )
               OrderModify(OrderTicket(),OrderOpenPrice(),NewStop,NewTarget,0);
            }
         
         }
      }
      
   //-- Look for initial entries
   if(TradeCount==0) 
      {
      //-- Long
        if (Total==0 && x!=iTime(0,0,0) && Bid>Hi && (Bid-Hi)<(5*point) 
                     && Bid>sar && Clo1>sar1 && Clo2>sar2 && dm<DemLevel1 && Cl==H)
         {
         if (Perc!=0) Lots=NormalizeDouble((AccountBalance()*(Perc/100)/LotC),2);
               {if (Lots>6) Lots=6;}
               if(InitStopLoss>0){SL1=Ask-InitStopLoss*point;}else {SL1=0;}
         OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage*multi, SL1,
	                Ask+(TakeProfit*point),"LONG Position Initiated",Magic,0,Navy);
         return(0);
         }
                       
      //-- Short
        if (Total==0 && x!=iTime(0,0,0) && Bid<Lo && (Lo-Bid)<(5*point) 
                     && Bid<sar && Clo1<sar1 && Clo2<sar2 && dm>DemLevel2 && Cl==L)
         {
         if (Perc!=0) Lots=NormalizeDouble((AccountBalance()*(Perc/100)/LotC),2);
               {if (Lots>6) Lots=6;}
               if(InitStopLoss>0){SL1=Bid+InitStopLoss*point;}else {SL1=0;}
         OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage*multi, SL1,
                   Bid-(TakeProfit*point),"SHORT Position Initiated",Magic,0,Red);
         return(0);
         }
      }   
      
   //-- Average Positions
   
      //-- average long
      if(TradeCount>0 && TradeCount<MaxTrades && TradeType==1 && (TradePrice-Ask)>=Level*point && Ask>sar)
              {
              Lotsi       = NormalizeDouble(Lotsi*Mult,2);
              AverageLong = (((MaxTrades-TradeCount)*Level)*point);
                if(AverageLong<11*point) AverageLong=11*point;
             if(StopLoss>0){SL=Ask-StopLoss*point;}else {SL=0;}
              OrderSend(Symbol(),OP_BUY,Lotsi,Ask,Slippage*multi, SL,
                        Ask+((TakeProfit)*point),"LONG Averaging Initiated",Magic,0,Green);
              }
      
      //-- average short
      if(TradeCount>0 && TradeCount<MaxTrades && TradeType==2 && (Bid-TradePrice)>=Level*point && Bid<sar)
              {
              Lotsi        = NormalizeDouble(Lotsi*Mult,2);
              AverageShort = (((MaxTrades-TradeCount)*Level)*point);
              if(AverageShort<11*point) AverageShort=11*point;
              if(StopLoss>0){SL=Bid+StopLoss*point;}else {SL=0;}
              OrderSend(Symbol(),OP_SELL,Lotsi,Bid,Slippage*multi, SL,
                        Bid-((TakeProfit)*point),"SHORT Averaging Initiated",Magic,0,DarkOrchid);
              }
      
            
      TradeCount=0;
      
      return(0);
      }
      
      void MoveATRTS()
{
   double ATR=iATR(Symbol(),ATRTSTimeFrame,ATRTSPeriod,1)*ATRTSFactor;
   int cnt,total=OrdersTotal();
   for(cnt=0;cnt<total;cnt++)
   {
      OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
      if(OrderType()<=OP_SELL&&OrderSymbol()==Symbol()&&OrderMagicNumber()==Magic)
      {
         if(OrderType()==OP_BUY)
         {
            if(NormalizeDouble(Ask-TrailingStep*point,digits)>NormalizeDouble(OrderOpenPrice()+15*point,digits))
            {                 
               if((NormalizeDouble(OrderStopLoss(),digits)<NormalizeDouble(Bid-ATR,digits))||(OrderStopLoss()==0))
               {
                  OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-ATR,digits),OrderTakeProfit(),0,Blue);
                  return(0);
               }
            }
         }
         else 
         {
            if(NormalizeDouble(Bid+TrailingStep*point,digits)<NormalizeDouble(OrderOpenPrice()-15*point,digits))
            {                 
               if((NormalizeDouble(OrderStopLoss(),digits)>(NormalizeDouble(Ask+ATR,digits)))||(OrderStopLoss()==0))
               {
                  OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+ATR,digits),OrderTakeProfit(),0,Red);
                  return(0);
               }
            }
         }
      }
   }
}
      
//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---