stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

Nanningbob 10.2 auto-trading EA
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=552
Page 18 of 54
Author:  SteveHopwood [ Tue May 22, 2012 8:53 am ]
Post subject:  Re: 10.2; the auto-trading EA is born.

phil_trade wrote:Hi Steve

I think TradeRange Test is missing in LookForWeeklyCrossRangeTrade()

Am'I right ?

Philippe
Oops. We are up to version 1n now. :lol:

Nice one again, Philippe. Thanks.

:D
Author:  quanttraderjoe [ Tue May 22, 2012 8:56 am ]
Post subject:  Re: 10.2; the auto-trading EA is born.

thanks Steve, and also Nanningbob the man himself, n all the gurus involved, i think this is a superb bot for trend trades n i like the fact that it is rarely caught out in reversals since BE kicks in early enough not to mention the numerous safeguards that hopefully keep our trades inline with the whales.
Author:  spotdespot [ Tue May 22, 2012 10:13 am ]
Post subject:  Re: 10.2; the auto-trading EA is born.

I seem unable to edit this latest version for some reason? Is there an obvious setting I am missing. I can load it in the MetaEditor but cannot make any changes as I usually do with the default settings......am I about to receive a dummy award?? :?
Author:  SteveHopwood [ Tue May 22, 2012 10:42 am ]
Post subject:  Re: 10.2; the auto-trading EA is born.

spotdespot wrote:I seem unable to edit this latest version for some reason? Is there an obvious setting I am missing. I can load it in the MetaEditor but cannot make any changes as I usually do with the default settings......am I about to receive a dummy award?? :?
You have to save it first, then reload it from within the platform.

:D
Author:  spotdespot [ Tue May 22, 2012 10:47 am ]
Post subject:  Re: 10.2; the auto-trading EA is born.

SteveHopwood wrote:
spotdespot wrote:I seem unable to edit this latest version for some reason? Is there an obvious setting I am missing. I can load it in the MetaEditor but cannot make any changes as I usually do with the default settings......am I about to receive a dummy award?? :?
You have to save it first, then reload it from within the platform.

:D
:shock: I'm not that much of a dummy Steve! I saved, restarted Empty4, recompiled it, saved as a different name, restarted again, tried a different criminal....same story. I might try the techies secret weapon & reboot.... :lol: I suspect somewhere my "system" thinks it is open already.....still doesn't quite make sense but what does with Empty4?

EDIT: Actually it turns out I am a dummy after all - who knew. For some reason the EA saved with "Read Only" attributes - now that would have been a good place to start looking when I couldn't edit it....doh. :roll:
Author:  SteveHopwood [ Tue May 22, 2012 11:37 am ]
Post subject:  Re: 10.2; the auto-trading EA is born.

spotdespot wrote:
SteveHopwood wrote:
spotdespot wrote:I seem unable to edit this latest version for some reason? Is there an obvious setting I am missing. I can load it in the MetaEditor but cannot make any changes as I usually do with the default settings......am I about to receive a dummy award?? :?
You have to save it first, then reload it from within the platform.

:D
:shock: I'm not that much of a dummy Steve! I saved, restarted Empty4, recompiled it, saved as a different name, restarted again, tried a different criminal....same story. I might try the techies secret weapon & reboot.... :lol: I suspect somewhere my "system" thinks it is open already.....still doesn't quite make sense but what does with Empty4?

EDIT: Actually it turns out I am a dummy after all - who knew. For some reason the EA saved with "Read Only" attributes - now that would have been a good place to start looking when I couldn't edit it....doh. :roll:
Don't you just love it when something simple takes an hour and a half? When I download an mq4 file into the editor, it always arrives as read-only. It has never saved as read-only before.

Aint the Empty4 and Windows combo fun?

Hey ho.

:D
Author:  alex_forex [ Tue May 22, 2012 3:52 pm ]
Post subject:  Re: 10.2; the auto-trading EA is born.

Fresh demo launched with V1N as you can see in my signature.

Cheers
Alex
Author:  phil_trade [ Tue May 22, 2012 5:49 pm ]
Post subject:  TradeWeeklyPivotCross

Hi Steve

You Described in post 1 the TradeWeeklyPivotCross

- Trading conditions are:
- either both Slopes must be ranging or any part of the D1 candle must be trading within the moving averages.

and the code is

Code: Select all

void LookForWeeklyCrossRangeTrade()
{
   //Called from LookForTradingOpportunities() if magic = 0, indicating no trades have been triggered by other systems.
   //Looks for D1/H4 Slopes both ranging, or some part of the D1 candle tradubg within the moving averages
   
   if (!TradeRange) return;//Usaer option to trade this way.
      
   //Only allow one open trade when the market is ranging.
   if (OpenTrades > 0) return;
   
   bool NowRanging = false;
   
   if (D1SlopeTrend == ranging && LtfSlopeTrend == ranging) NowRanging = true;
   if (!NowRanging)
   {
      double Hma = GetHighestMovingAverage(PERIOD_D1);
      double Lma = GetLowestMovingAverage(PERIOD_D1);
   }//if (!NowRanging)
   
   //Is any part of the D1 candle trading within the moving averages?
   if (iLow(NULL, PERIOD_D1, 0) > Hma || iHigh(NULL, PERIOD_D1, 0) < Lma) return;
I suspect a problem if NowRanging =true because D1Slope and LtfSlopeTrend are ranging
This code line are not executed
if (!NowRanging)
{
double Hma = GetHighestMovingAverage(PERIOD_D1);
double Lma = GetLowestMovingAverage(PERIOD_D1);
}//if (!NowRanging)

-> Hma and Lma not declared and suppose = 0 ??
-> iLow(NULL, PERIOD_D1, 0) > Hma always true
so if D1Slope and LtfSlope ranging, it's impossible to have WPC range Trade

I suggest
-> Always declare Variable at top of Function/Procedure
and/or move code like this

Code: Select all

   if (!NowRanging)
   {
      double Hma = GetHighestMovingAverage(PERIOD_D1);
      double Lma = GetLowestMovingAverage(PERIOD_D1);
      
   //Is any part of the D1 candle trading within the moving averages?
   if (iLow(NULL, PERIOD_D1, 0) > Hma || iHigh(NULL, PERIOD_D1, 0) < Lma) return;      
      
   }//if (!NowRanging)
otherwise we can't have WPC trade on only D1Slope/LtfSlope Ranging

Am I right ?

Philippe
Author:  phil_trade [ Tue May 22, 2012 7:22 pm ]
Post subject:  Re: 10.2; the auto-trading EA is born.

Steve

I had from time to time error 130 on modifyOrder for SL and TP like for BUY EURCHF 22/05/2012 22H13 GMT WPCrange trade on SlopeRanging because SL and TP too near from Bid.
Bid 1.20117 and R1 1.2011 R2 1.2013 S1 1.2003 S2 1.2001

So the trade was passed without SL and TP !

Some Broker and some pairs have very wide STOPLEVEL (40 pips minimum for EURCHF)

so I suggest to modify code like below. This solve for EURCHF with a trade with SL at 1.20055 and TP 1.20157 but may be you will prefer not to trade when Bid too near calculated SL and TP.

Philippe

Code: Select all

double CalculateStopLoss(int type)
{
   //Returns the stop loss for use in LookForTradingOpps and InsertMissingStopLoss
   double stop, price;


   RefreshRates();
   
   double Stoplevel = MarketInfo(Symbol(),MODE_STOPLEVEL);

/*
#define  BbRangeTrade "BB Range trade"
*/
   if (type == OP_BUY)
   {
      price = Ask;
      if (StopLoss > 0) 
      {
         stop = NormalizeDouble(price - (StopLoss * Point), Digits);
         HiddenStopLoss = stop;
      }//if (StopLoss > 0) 

      if (StopLoss == 0)
      {
         //BB Range trade. Use Bb extent
         if (TradeOrigin == BbRangeTrade)
         {
            double extent = BbUpper - BbLower;
            stop = NormalizeDouble(BbLower - extent, Digits);
         }//if (TradeOrigin == BbRangeTrade)

         //Wpc range trade. Uses S1/S2 as sl
         if (TradeOrigin == WpcRangeTrade)
         {
            stop = WS2;
            if (VolatilityGroup < 4) stop = WS1;
         }//if (TradeOrigin == WpcRangeTrade)
      
         //D1 trend trade
         if (TradeOrigin == D1TrendTrade)
         {
            stop = MS2;
            if (VolatilityGroup < 4) stop = MS1;
         }//if (TradeOrigin == D1TrendTrade)
            
         //H4 trend trade
         if (TradeOrigin == H4TrendTrade)
         {
            stop = WS2;
            if (VolatilityGroup < 4) stop = WS1;
         }//if (TradeOrigin == H4TrendTrade)
         
       
      }//if (StopLoss == 0)
            
      if (HiddenPips > 0 && stop > 0) stop = NormalizeDouble(stop - (HiddenPips * Point), Digits);

      // Control stop level minima
      if (Bid-stop <= Stoplevel*Point) 
      {
      stop = Bid - (Stoplevel*Point);
      }

   }//if (type == OP_BUY)
   


   if (type == OP_SELL)
   {
      price = Bid;
      if (StopLoss > 0) 
      {
         stop = NormalizeDouble(price + (StopLoss * Point), Digits);
         HiddenStopLoss = stop;         
      }//if (StopLoss > 0) 

      if (StopLoss == 0)
      {
         //BB Range trade. Use Bb extent
         if (TradeOrigin == BbRangeTrade)
         {
            extent = BbUpper - BbLower;
            stop = NormalizeDouble(BbUpper + extent, Digits);
         }//if (TradeOrigin == BbRangeTrade)

         //Wpc range trade. Uses R1/R2 as sl
         if (TradeOrigin == WpcRangeTrade)
         {
            stop = WR2;
            if (VolatilityGroup < 4) stop = WR1;
         }//if (TradeOrigin == WpcRangeTrade)

         //D1 trend trade
         if (TradeOrigin == D1TrendTrade)
         {
            stop = MR2;
            if (VolatilityGroup < 4) stop = MR1;
         }//if (TradeOrigin == D1TrendTrade)

         //H4 trend trade
         if (TradeOrigin == H4TrendTrade)
         {
            stop = WR2;
            if (VolatilityGroup < 4) stop = WR1;
         }//if (TradeOrigin == H4TrendTrade)
      
    
      }//if (StopLoss == 0)
      
      if (HiddenPips > 0 && stop > 0) stop = NormalizeDouble(stop + (HiddenPips * Point), Digits);

      // Control stop level minima
      if (stop-Ask <= Stoplevel*Point) 
      {
      stop = Ask + (Stoplevel*Point);
      }

   }//if (type == OP_SELL)
   
   return(stop);
   
}//End double CalculateStopLoss(int type)

double CalculateTakeProfit(int type, string origin)
{
   //Returns the stop loss for use in LookForTradingOpps and InsertMissingStopLoss
   double take, price;

   RefreshRates();
   
   double Stoplevel = MarketInfo(Symbol(),MODE_STOPLEVEL);   
   
   if (type == OP_BUY)
   {
      price = Ask;
      if (TakeProfit > 0) 
      {
         take = NormalizeDouble(price + (TakeProfit * Point), Digits);
         HiddenTakeProfit = take;
      }//if (TakeProfit > 0) 

      //D1 trend trade
      if (TradeOrigin == D1TrendTrade)
      {
         //Override any take profit choice if D1SlopeTrend is buy and hold
         if (D1SlopeTrend == buyhold)
         {
            take = 0;
            AdaptedBreakEven = true;
            AdaptedJumpingStop = true;
         }//if (D1SlopeTrend == buyhold)

         //If D1 slope is not buy and hold, then set a tp based on the next full resistance level
         if (D1SlopeTrend != buyhold)
         {
            //Work down through the Monthly Resistance levels until Bid is lower than the resistance. 
            //I have assumed that the market will be above the support levels, and can amend this easily if not.
            if (price < MR3)
            {
               if (MR3 - price >= (MinD1TrendTradeTpPips * Point) ) take = MR3;
            }//if (price < MR3)
            
            if (price < MR2)
            {
               if (MR2 - price >= (MinD1TrendTradeTpPips * Point) ) take = MR2;
            }//if (price < MR3)

            if (price < MR1)
            {
               if (MR1 - price >= (MinD1TrendTradeTpPips * Point) ) take = MR1;
            }//if (price < MR3)
            
            if (price < MonthlyPivot)
            {
               if (MonthlyPivot - price >= (MinD1TrendTradeTpPips * Point) ) take = MonthlyPivot;
            }//if (price < MonthlyPivot)
         }//if (D1SlopeTrend == buyhold)
         
      }//if (TradeOrigin = D1Trend)
      
      //H4 trend trade
      if (TradeOrigin == H4TrendTrade)
      {
         //Override any take profit choice if D1SlopeTrend is buy and hold
         if (D1SlopeTrend == buyhold)
         {
            take = 0;
            AdaptedBreakEven = true;
            AdaptedJumpingStop = true;
         }//if (D1SlopeTrend == buyhold)
         
         //D1 trend is not buy and hold, so set a tp based on the next resistance. 
         //This is weekly R1 for pairs in groups 1 to 3, R2 for the others.
         if (D1SlopeTrend == buy)
         {
            take = WR2;
            if (VolatilityGroup < 4) take = WR1;
         }//if (D1SlopeTrend == buy)         
      }//if (TradeOrigin == H4TrendTrade)
      
      //BB Range trade. Use Weekly pivot tp. Range trade should only be sent at 
      //MinimumRangeTakeProfit from the weekly pivot
      if (TradeOrigin == BbRangeTrade)
      {
         take = WeeklyPivot;         
      }//if (TradeOrigin == RangeTrade)
      
      //Wpc range trade. Uses R1/R2 as tp
      if (TradeOrigin == WpcRangeTrade)
      {
         take = WR2;
         if (VolatilityGroup < 4) take = WR1;
      }//if (TradeOrigin == WpcRangeTrade)
      
      if (HiddenPips > 0 && take > 0) take = NormalizeDouble(take + (HiddenPips * Point), Digits);

       // Control stop level minima
       if (take-Ask <= Stoplevel*Point) 
       {
       take = Ask + (Stoplevel*Point);
       }


   }//if (type == OP_BUY)
   
   if (type == OP_SELL)
   {
      price = Bid;
      if (TakeProfit > 0) 
      {
         take = NormalizeDouble(price - (TakeProfit * Point), Digits);
         HiddenTakeProfit = take;         
      }//if (TakeProfit > 0) 

      if (TradeOrigin == D1TrendTrade)
      {
         //Override any take profit choice if D1SlopeTrend is sell and hold
         if (D1SlopeTrend == sellhold)
         {
            take = 0;
            AdaptedBreakEven = true;
            AdaptedJumpingStop = true;
         }//if (D1SlopeTrend == buyhold)

         //If D1 slope is not sell and hold, then set a tp based on the next full support level
         if (D1SlopeTrend != buyhold)
         {
            //Work up through the Monthly support levels until Bid is higher than support. I have assumed that the
            //market will be below the resistance levels, and can amend this easily if not.
            if (price > MS3)
            {
               if (price - MS3 >= (MinD1TrendTradeTpPips * Point) ) take = MS3;
            }//if (price > MS3)
            
            if (price > MS2)
            {
               if (price - MS2 >= (MinD1TrendTradeTpPips * Point) ) take = MS2;
            }//if (price > MS2)
            
            if (price > MS1)
            {
               if (price - MS1 >= (MinD1TrendTradeTpPips * Point) ) take = MS1;
            }//if (price > MS1)
            
            if (price > MonthlyPivot)
            {
               if (price - MonthlyPivot >= (MinD1TrendTradeTpPips * Point) ) take = MonthlyPivot;
            }//if (price > MonthlyPivot)
         }//if (D1SlopeTrend == buyhold)
      }//if (TradeOrigin == D1Trend)
      
      //H4 trend trade
      if (TradeOrigin == H4TrendTrade)
      {
         //Override any take profit choice if D1SlopeTrend is buy and hold
         if (D1SlopeTrend == sellhold)
         {
            take = 0;
            AdaptedBreakEven = true;
            AdaptedJumpingStop = true;
         }//if (D1SlopeTrend == buyhold)
         
         //D1 trend is not buy and hold, so set a tp based on the next resistance. 
         //This is weekly R1 for pairs in groups 1 to 3, R2 for the others.
         if (D1SlopeTrend == sell)
         {
            take = WS2;
            if (VolatilityGroup < 4) take = WS1;
         }//if (D1SlopeTrend == sell)
      }//if (TradeOrigin == H4TrendTrade)

      //BB Range trade. Use Weekly pivot tp. Range trade should only be sent at 
      //MinimumRangeTakeProfit from the weekly pivot
      if (TradeOrigin == BbRangeTrade)
      {
         take = WeeklyPivot;         
      }//if (TradeOrigin == RangeTrade)

      //Wpc range trade. Uses S1/S2 as tp
      if (TradeOrigin == WpcRangeTrade)
      {
         take = WS2;
         if (VolatilityGroup < 4) take = WS1;
      }//if (TradeOrigin == WpcRangeTrade)

      if (HiddenPips > 0 && take > 0) take = NormalizeDouble(take - (HiddenPips * Point), Digits);

       // Control stop level minima
       if (Bid-take <= Stoplevel*Point) 
       {
       take = Bid - (Stoplevel*Point);
       }


   }//if (type == OP_SELL)
   
   return(take);
   
}//End double CalculateTakeProfit(int type, string origin)
Author:  SteveHopwood [ Tue May 22, 2012 8:37 pm ]
Post subject:  Re: 10.2; the auto-trading EA is born.

phil_trade wrote:Steve

I had from time to time error 130 on modifyOrder for SL and TP like for BUY EURCHF 22/05/2012 22H13 GMT WPCrange trade on SlopeRanging because SL and TP too near from Bid.
Bid 1.20117 and R1 1.2011 R2 1.2013 S1 1.2003 S2 1.2001

So the trade was passed without SL and TP !

Some criminal and some pairs have very wide STOPLEVEL (40 pips minimum for EURCHF)

so I suggest to modify code like below. This solve for EURCHF with a trade with SL at 1.20055 and TP 1.20157 but may be you will prefer not to trade when Bid too near calculated SL and TP.

Philippe

Code: Select all

double CalculateStopLoss(int type)
{
   //Returns the stop loss for use in LookForTradingOpps and InsertMissingStopLoss
   double stop, price;


   RefreshRates();
   
   double Stoplevel = MarketInfo(Symbol(),MODE_STOPLEVEL);

/*
#define  BbRangeTrade "BB Range trade"
*/
   if (type == OP_BUY)
   {
      price = Ask;
      if (StopLoss > 0) 
      {
         stop = NormalizeDouble(price - (StopLoss * Point), Digits);
         HiddenStopLoss = stop;
      }//if (StopLoss > 0) 

      if (StopLoss == 0)
      {
         //BB Range trade. Use Bb extent
         if (TradeOrigin == BbRangeTrade)
         {
            double extent = BbUpper - BbLower;
            stop = NormalizeDouble(BbLower - extent, Digits);
         }//if (TradeOrigin == BbRangeTrade)

         //Wpc range trade. Uses S1/S2 as sl
         if (TradeOrigin == WpcRangeTrade)
         {
            stop = WS2;
            if (VolatilityGroup < 4) stop = WS1;
         }//if (TradeOrigin == WpcRangeTrade)
      
         //D1 trend trade
         if (TradeOrigin == D1TrendTrade)
         {
            stop = MS2;
            if (VolatilityGroup < 4) stop = MS1;
         }//if (TradeOrigin == D1TrendTrade)
            
         //H4 trend trade
         if (TradeOrigin == H4TrendTrade)
         {
            stop = WS2;
            if (VolatilityGroup < 4) stop = WS1;
         }//if (TradeOrigin == H4TrendTrade)
         
       
      }//if (StopLoss == 0)
            
      if (HiddenPips > 0 && stop > 0) stop = NormalizeDouble(stop - (HiddenPips * Point), Digits);

      // Control stop level minima
      if (Bid-stop <= Stoplevel*Point) 
      {
      stop = Bid - (Stoplevel*Point);
      }

   }//if (type == OP_BUY)
   


   if (type == OP_SELL)
   {
      price = Bid;
      if (StopLoss > 0) 
      {
         stop = NormalizeDouble(price + (StopLoss * Point), Digits);
         HiddenStopLoss = stop;         
      }//if (StopLoss > 0) 

      if (StopLoss == 0)
      {
         //BB Range trade. Use Bb extent
         if (TradeOrigin == BbRangeTrade)
         {
            extent = BbUpper - BbLower;
            stop = NormalizeDouble(BbUpper + extent, Digits);
         }//if (TradeOrigin == BbRangeTrade)

         //Wpc range trade. Uses R1/R2 as sl
         if (TradeOrigin == WpcRangeTrade)
         {
            stop = WR2;
            if (VolatilityGroup < 4) stop = WR1;
         }//if (TradeOrigin == WpcRangeTrade)

         //D1 trend trade
         if (TradeOrigin == D1TrendTrade)
         {
            stop = MR2;
            if (VolatilityGroup < 4) stop = MR1;
         }//if (TradeOrigin == D1TrendTrade)

         //H4 trend trade
         if (TradeOrigin == H4TrendTrade)
         {
            stop = WR2;
            if (VolatilityGroup < 4) stop = WR1;
         }//if (TradeOrigin == H4TrendTrade)
      
    
      }//if (StopLoss == 0)
      
      if (HiddenPips > 0 && stop > 0) stop = NormalizeDouble(stop + (HiddenPips * Point), Digits);

      // Control stop level minima
      if (stop-Ask <= Stoplevel*Point) 
      {
      stop = Ask + (Stoplevel*Point);
      }

   }//if (type == OP_SELL)
   
   return(stop);
   
}//End double CalculateStopLoss(int type)

double CalculateTakeProfit(int type, string origin)
{
   //Returns the stop loss for use in LookForTradingOpps and InsertMissingStopLoss
   double take, price;

   RefreshRates();
   
   double Stoplevel = MarketInfo(Symbol(),MODE_STOPLEVEL);   
   
   if (type == OP_BUY)
   {
      price = Ask;
      if (TakeProfit > 0) 
      {
         take = NormalizeDouble(price + (TakeProfit * Point), Digits);
         HiddenTakeProfit = take;
      }//if (TakeProfit > 0) 

      //D1 trend trade
      if (TradeOrigin == D1TrendTrade)
      {
         //Override any take profit choice if D1SlopeTrend is buy and hold
         if (D1SlopeTrend == buyhold)
         {
            take = 0;
            AdaptedBreakEven = true;
            AdaptedJumpingStop = true;
         }//if (D1SlopeTrend == buyhold)

         //If D1 slope is not buy and hold, then set a tp based on the next full resistance level
         if (D1SlopeTrend != buyhold)
         {
            //Work down through the Monthly Resistance levels until Bid is lower than the resistance. 
            //I have assumed that the market will be above the support levels, and can amend this easily if not.
            if (price < MR3)
            {
               if (MR3 - price >= (MinD1TrendTradeTpPips * Point) ) take = MR3;
            }//if (price < MR3)
            
            if (price < MR2)
            {
               if (MR2 - price >= (MinD1TrendTradeTpPips * Point) ) take = MR2;
            }//if (price < MR3)

            if (price < MR1)
            {
               if (MR1 - price >= (MinD1TrendTradeTpPips * Point) ) take = MR1;
            }//if (price < MR3)
            
            if (price < MonthlyPivot)
            {
               if (MonthlyPivot - price >= (MinD1TrendTradeTpPips * Point) ) take = MonthlyPivot;
            }//if (price < MonthlyPivot)
         }//if (D1SlopeTrend == buyhold)
         
      }//if (TradeOrigin = D1Trend)
      
      //H4 trend trade
      if (TradeOrigin == H4TrendTrade)
      {
         //Override any take profit choice if D1SlopeTrend is buy and hold
         if (D1SlopeTrend == buyhold)
         {
            take = 0;
            AdaptedBreakEven = true;
            AdaptedJumpingStop = true;
         }//if (D1SlopeTrend == buyhold)
         
         //D1 trend is not buy and hold, so set a tp based on the next resistance. 
         //This is weekly R1 for pairs in groups 1 to 3, R2 for the others.
         if (D1SlopeTrend == buy)
         {
            take = WR2;
            if (VolatilityGroup < 4) take = WR1;
         }//if (D1SlopeTrend == buy)         
      }//if (TradeOrigin == H4TrendTrade)
      
      //BB Range trade. Use Weekly pivot tp. Range trade should only be sent at 
      //MinimumRangeTakeProfit from the weekly pivot
      if (TradeOrigin == BbRangeTrade)
      {
         take = WeeklyPivot;         
      }//if (TradeOrigin == RangeTrade)
      
      //Wpc range trade. Uses R1/R2 as tp
      if (TradeOrigin == WpcRangeTrade)
      {
         take = WR2;
         if (VolatilityGroup < 4) take = WR1;
      }//if (TradeOrigin == WpcRangeTrade)
      
      if (HiddenPips > 0 && take > 0) take = NormalizeDouble(take + (HiddenPips * Point), Digits);

       // Control stop level minima
       if (take-Ask <= Stoplevel*Point) 
       {
       take = Ask + (Stoplevel*Point);
       }


   }//if (type == OP_BUY)
   
   if (type == OP_SELL)
   {
      price = Bid;
      if (TakeProfit > 0) 
      {
         take = NormalizeDouble(price - (TakeProfit * Point), Digits);
         HiddenTakeProfit = take;         
      }//if (TakeProfit > 0) 

      if (TradeOrigin == D1TrendTrade)
      {
         //Override any take profit choice if D1SlopeTrend is sell and hold
         if (D1SlopeTrend == sellhold)
         {
            take = 0;
            AdaptedBreakEven = true;
            AdaptedJumpingStop = true;
         }//if (D1SlopeTrend == buyhold)

         //If D1 slope is not sell and hold, then set a tp based on the next full support level
         if (D1SlopeTrend != buyhold)
         {
            //Work up through the Monthly support levels until Bid is higher than support. I have assumed that the
            //market will be below the resistance levels, and can amend this easily if not.
            if (price > MS3)
            {
               if (price - MS3 >= (MinD1TrendTradeTpPips * Point) ) take = MS3;
            }//if (price > MS3)
            
            if (price > MS2)
            {
               if (price - MS2 >= (MinD1TrendTradeTpPips * Point) ) take = MS2;
            }//if (price > MS2)
            
            if (price > MS1)
            {
               if (price - MS1 >= (MinD1TrendTradeTpPips * Point) ) take = MS1;
            }//if (price > MS1)
            
            if (price > MonthlyPivot)
            {
               if (price - MonthlyPivot >= (MinD1TrendTradeTpPips * Point) ) take = MonthlyPivot;
            }//if (price > MonthlyPivot)
         }//if (D1SlopeTrend == buyhold)
      }//if (TradeOrigin == D1Trend)
      
      //H4 trend trade
      if (TradeOrigin == H4TrendTrade)
      {
         //Override any take profit choice if D1SlopeTrend is buy and hold
         if (D1SlopeTrend == sellhold)
         {
            take = 0;
            AdaptedBreakEven = true;
            AdaptedJumpingStop = true;
         }//if (D1SlopeTrend == buyhold)
         
         //D1 trend is not buy and hold, so set a tp based on the next resistance. 
         //This is weekly R1 for pairs in groups 1 to 3, R2 for the others.
         if (D1SlopeTrend == sell)
         {
            take = WS2;
            if (VolatilityGroup < 4) take = WS1;
         }//if (D1SlopeTrend == sell)
      }//if (TradeOrigin == H4TrendTrade)

      //BB Range trade. Use Weekly pivot tp. Range trade should only be sent at 
      //MinimumRangeTakeProfit from the weekly pivot
      if (TradeOrigin == BbRangeTrade)
      {
         take = WeeklyPivot;         
      }//if (TradeOrigin == RangeTrade)

      //Wpc range trade. Uses S1/S2 as tp
      if (TradeOrigin == WpcRangeTrade)
      {
         take = WS2;
         if (VolatilityGroup < 4) take = WS1;
      }//if (TradeOrigin == WpcRangeTrade)

      if (HiddenPips > 0 && take > 0) take = NormalizeDouble(take - (HiddenPips * Point), Digits);

       // Control stop level minima
       if (Bid-take <= Stoplevel*Point) 
       {
       take = Bid - (Stoplevel*Point);
       }


   }//if (type == OP_SELL)
   
   return(take);
   
}//End double CalculateTakeProfit(int type, string origin)
Or people can use HiddenPips to have their stop loss pretty much where they want.

Still, better to have correct than incorrect code and I am not one to turn down free code, so V 1o in post 1 has this mod. Thanks again.

:D
All times are UTC Page 18 of 54