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

Awesome - original version
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=5232
Page 38 of 46
Author:  dreambig2 [ Fri Oct 06, 2017 10:42 am ]
Post subject:  Awesome - original version

DigitalCrypto » Tue Oct 03, 2017 9:31 pm wrote:Yes it is. I know this because every time I look at the FXChoice crim I cringe with disgust on their "ECN spread" of > 3-4 pips. And when I see Traders Way crim I think who in the hell charges -14.04 swaps?!

You guys are lucky to be able to use GP.
Same here...i'm watching my GP demos marching along and same setups up on TW and FXC having issues...totally sucks...expat looking better all the time....trying diff settings to overcome. :arrrg:
Author:  DigitalCrypto [ Mon Oct 09, 2017 6:42 pm ]
Post subject:  Awesome - original version

Still having problems with AO losing track of open trades when EA settings are changed/reloaded. :arrrg:

It's beyond me at this point...I will keep looking.
Author:  4xtn [ Mon Oct 16, 2017 1:05 pm ]
Post subject:  Awesome - original version

Having some trouble with 'Close on opposite FB / Only when SS agrees' - it appears Awesome closes on first opposite FB. Also 'Minimum distance between signals in pips' is not observed. Any ideas where to look for fixes? :?:
Author:  jade768 [ Mon Oct 16, 2017 1:14 pm ]
Post subject:  Awesome - original version

4xtn » Mon Oct 16, 2017 1:05 pm wrote:Having some trouble with 'Close on opposite FB / Only when SS agrees' - it appears Awesome closes on first opposite FB. Also 'Minimum distance between signals in pips' is not observed. Any ideas where to look for fixes? :?:
[cc] should be [pairIndex] for the SS array

Code: Select all

if (!OnlyCloseWhenSuperSlopeAgrees[cc] || SsColour[cc] == red ) => if (!OnlyCloseWhenSuperSlopeAgrees[cc] || SsColour[pairIndex] == red )
same for the blue one
Author:  SteveHopwood [ Mon Oct 16, 2017 2:28 pm ]
Post subject:  Awesome - original version

jade768 » Mon Oct 16, 2017 1:14 pm wrote:
[cc] should be [pairIndex] for the SS array

Code: Select all

if (!OnlyCloseWhenSuperSlopeAgrees[cc] || SsColour[cc] == red ) => if (!OnlyCloseWhenSuperSlopeAgrees[cc] || SsColour[pairIndex] == red )
same for the blue one
Nice spot jade768. Thanks.

Here is a replacement for the current bool LookForTradeClosure(int ticket) function. I have changed one of the variables so the name reflects its use.

Code: Select all

bool LookForTradeClosure(int ticket)
{
   //Close the trade if the close conditions are met.
   //Called from within CountOpenTrades(). Returns true if a close is needed and succeeds, so that COT can increment TimeFrameIndex,
   //else returns false
   
   if (!BetterOrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES) ) 
      return(true);
   if (BetterOrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES) )
      if (OrderCloseTime() > 0)
          return(true);
   
   bool CloseThisTrade = false;
   
   //We need to know which time frame this trade belongs to
   int TimeFrameIndex = ExtractIndexFromTradeComment(OrderSymbol(), OrderComment() );
   
   //Opposite direction FB
   //We need the FB array index
   //Amended FB code
   int pairIndex = 0;
   if (CloseOnOppositeFB[TimeFrameIndex])
      pairIndex = ExtractTradePairIndex(OrderSymbol(), TimeFrameIndex);
   
   ///////////////////////////////////////////////////////////////////////////////////////////////////////////
   if (OrderType() == OP_BUY || OrderType() == OP_BUYSTOP)
   {
      //TP
      if (bid >= OrderTakeProfit() ) 
         if (!CloseEnough(OrderTakeProfit(), 0) ) 
            CloseThisTrade = true;
      //SL
      if (bid <= OrderStopLoss() )
       if (!CloseEnough(OrderStopLoss(), 0) ) 
         CloseThisTrade = true;

      
      //Opposite direction FB
      if (CloseOnOppositeFB[TimeFrameIndex])
         if (!OnlyCloseWhenSuperSlopeAgrees[TimeFrameIndex] || SsColour[pairIndex] == red )
            if (FbStatus[pairIndex][TimeFrameIndex] == fbdownarrowtradable || FbStatus[pairIndex][TimeFrameIndex] == fbdownarrowuntradable)//Amended FB code
               CloseThisTrade = true;
      
     
      
   }//if (OrderType() == OP_BUY || OrderType() == OP_BUYSTOP)
   
   
   ///////////////////////////////////////////////////////////////////////////////////////////////////////////
   if (OrderType() == OP_SELL || OrderType() == OP_SELLSTOP)
   {
      //TP
      if (ask <= OrderTakeProfit() )
         if (!CloseEnough(OrderTakeProfit(), 0) ) 
            CloseThisTrade = true;
      //SL
      if (ask >= OrderStopLoss() ) 
         if (!CloseEnough(OrderStopLoss(), 0) ) 
            CloseThisTrade = true;


      //Opposite direction FB
      if (CloseOnOppositeFB[TimeFrameIndex])
         if (!OnlyCloseWhenSuperSlopeAgrees[TimeFrameIndex] || SsColour[pairIndex] == blue )
            if (FbStatus[pairIndex][TimeFrameIndex] == fbuparrowtradable || FbStatus[pairIndex][TimeFrameIndex] == fbuparrowuntradable)//Amended FB code
               CloseThisTrade = true;
      
      
      
      
   }//if (OrderType() == OP_SELL || OrderType() == OP_SELLSTOP)
   
   ///////////////////////////////////////////////////////////////////////////////////////////////////////////
   if (CloseThisTrade)
   {
      bool result = false;
      
      if (OrderType() < 2)//Market orders
         result = CloseOrder(ticket, __FUNCTION__,  OrderLots(), ocm);
      else
         result = OrderDelete(ticket, clrNONE);
            
      //Actions when trade close succeeds
      if (result)
      {
         TicketNo = -1;//TicketNo is the most recently trade opened, so this might need editing in a multi-trade EA
         OpenTrades--;//Rather than OpenTrades = 0 to cater for multi-trade EA's
         return(true);//Makes CountOpenTrades increment TimeFrameIndex to avoid missing out ccounting a trade
      }//if (result)
   
      //Actions when trade close fails
      if (!result)
      {
         return(false);//Do not increment TimeFrameIndex
      }//if (!result)
   }//if (CloseThisTrade)
   
   //Got this far, so no trade closure
   return(false);//Do not increment TimeFrameIndex
   
}//End bool LookForTradeClosure()
I will post an update to post 1 when I have looked at 4xtn's thingy about the minimum pips distance. I have probably over-complicated something that is simple to accomplish - just as I did when coding Candle Power.

:xm:
Author:  SteveHopwood [ Mon Oct 16, 2017 2:38 pm ]
Post subject:  Awesome - original version

V 1o is in post 1 with the fix from my previous post.

I cannot see anything wrong with the code that ensures a minimum distance between trades.

:xm:
Author:  4xtn [ Mon Oct 16, 2017 3:01 pm ]
Post subject:  Awesome - original version

SteveHopwood » Mon Oct 16, 2017 2:38 pm wrote:V 1o is in post 1 with the fix from my previous post.

I cannot see anything wrong with the code that ensures a minimum distance between trades.

:xm:
Steve, I forgot to mention I'm sending pendings.. Maybe Awesome is looking for live trades only?

Cheers
Tom
Author:  SteveHopwood [ Mon Oct 16, 2017 3:40 pm ]
Post subject:  Awesome - original version

4xtn » Mon Oct 16, 2017 3:01 pm wrote:
Steve, I forgot to mention I'm sending pendings.. Maybe Awesome is looking for live trades only?

Cheers
Tom
I just had a look and yes, the code only searches for market trades. I will have a think and post again later.

:xm:
Author:  SteveHopwood [ Mon Oct 16, 2017 5:28 pm ]
Post subject:  Awesome - original version

V 1q is in post 1, with an attempted fix for the minimum pips between trades thingy. The 'simple' method used by Candle Power is nowhere near so simple here as the code had to cope with multi-pairs and time frames.

DIYers and bloop spotters, I have added this function:

Code: Select all

bool EnoughDistance(string symbol, int magic, int tfIndex, int type, double price)
{
   //Returns false if the is < MinDistanceBetweenTradesPips
   //between the proposed order price and the nearest order open prices.
   
   double pips = 0;
   
   //No market order yet
   if (type == OP_BUY)
      if (!BuyOpen)
         return(true);
      
   if (type == OP_SELL)
      if (!SellOpen)
         return(true);
      
   for (int cc = OrdersTotal() - 1; cc >= 0; cc--)
   {
      if (!BetterOrderSelect(cc, SELECT_BY_POS, MODE_TRADES) ) continue;
      if (OrderSymbol() != symbol ) continue;
      if (OrderMagicNumber() != magic) continue;
      
      //Are we looking for some sort of buy order?
      if (type == OP_BUY)
         if (OrderType() != OP_BUY)
            if (OrderType() != OP_BUYSTOP)
               if (OrderType() != OP_BUYLIMIT)
                  continue;
      
      //Are we looking for some sort of sell order?
      if (type == OP_SELL)
         if (OrderType() != OP_SELL)
            if (OrderType() != OP_SELLSTOP)
               if (OrderType() != OP_SELLLIMIT)
                  continue;
      
      //Gopt this far so Awesome owns the trade. Is there sufficient distance
      //between it and the proposed order price?
      pips = MathAbs(price - OrderOpenPrice() ) * factor;
      if (pips < MinimumDistanceBetweenSignalsPips[tfIndex])
         return(false);
   }//for (int cc = OrdersTotal() - 1; cc >= 0; cc--)

 
   //Got here, so OK to trade
   return(true);

   

}//End bool EnoughDistance(int type, double price)

Then do a search for "//We need to check that the market is sufficient distance from the highest/lowest open trade" and copy this over the subsequent code block:

Code: Select all

               //Take every trade signal
               //We need to check that the market is sufficient distance from the highest/lowest open trade
               if (OpenTrades > 0)
               {
                  double BuyPrice = ask;
                  if (!ImmediateMarketTrades[tfIndex])
                     BuyPrice = NormalizeDouble(ask + (TradeBuffers[tfIndex] / factor), digits);//Stop order price
                  
                  double SellPrice = bid;
                  if (!ImmediateMarketTrades[tfIndex])
                     SellPrice = NormalizeDouble(bid - (TradeBuffers[tfIndex] / factor), digits);//Stop order price
                     
                  //Buy signal. Market must be above the highest open buy price or below the lowest.
                  if (FbStatus[pairsIndex][tfIndex] == fbuparrowtradable)//Amended FB code
                     if (!EnoughDistance(symbol, MagicNumbers[tfIndex], tfIndex, OP_BUY, BuyPrice) )
                        FbStatus[pairsIndex][tfIndex] = fbuparrowuntradable;//Amended FB code
                  
                  //Sell signal. Market must be above the lowest open sell price or above the highest.
                  if (FbStatus[pairsIndex][tfIndex] == fbdownarrowtradable)//Amended FB code
                     if (!EnoughDistance(symbol, MagicNumbers[tfIndex], tfIndex, OP_SELL, SellPrice) )
                        FbStatus[pairsIndex][tfIndex] = fbdownarrowuntradable;//Amended FB code
                           
               }//if (OpenTrades > 0)
:xm:
Author:  DigitalCrypto [ Wed Oct 18, 2017 11:20 am ]
Post subject:  Awesome - original version

Steve I know you are busy this week. I'm the same way when it comes to kids. Any time I get the opportunity to help out kids it's a great feeling. I can't find fault with that.

I wanted to post a suggestion in here for a later date. I may get knee capped for it but that's ok. This is very good stuff.

I have an EA that is similar to CP. But one thing I do differently is instead of a basket TP per symbol I will use say +0.25% Account Profit as a trigger to lock in profits and start trailing them out. The result is a bit better money on a position that I would otherwise have let gone to basket close when I could have squeezed a few more pips out of that multi-trade position. The rewards of course are exponential in nature.

I also won't add any new trades to a profitable position while it's trailing out.
All times are UTC Page 38 of 46