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

Ghostrider
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=5942
Page 5 of 12
Author:  Fourxxxx [ Wed Oct 28, 2020 11:47 am ]
Post subject:  Ghostrider

Hope I am not out of line posting this here.

I think that the trailing stop is not working as expected.

These 2 lines adding or subtracting from the current StopLoss rather than the Bid.

3683

Code: Select all

NewStop = NormalizeDouble(sl + (TrailingStopPips / factor), Digits)
3703

Code: Select all

NewStop = NormalizeDouble(sl - (TrailingStopPips / factor), Digits);
With the changes here it seems to be working as intended.

Code: Select all

void TrailingStopLoss(int ticket)
{

   //Security check
   if (!BetterOrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES))
      return;
   
   if (OrderProfit() < 0) return;//Nothing to do
   string LineName = SlPrefix + DoubleToStr(OrderTicket(), 0);
   double sl = ObjectGet(LineName, OBJPROP_PRICE1);
   //if (CloseEnough(sl, 0) ) return;//No line, so nothing to do
   if (CloseEnough(sl, 0) ) sl = OrderStopLoss();
   double NewStop;
   bool modify=false;
   bool result;
   
    if (OrderType()==OP_BUY)
       {
          if (sl < OrderOpenPrice() ) return;//Not at breakeven yet
          // Increment sl by sl + TrailingStopPips.
          if (CloseEnough(sl, 0) ) sl = MathMax(OrderStopLoss(), OrderOpenPrice());
          
          //Check that the market is sufficiently in profit to continue
          if (Bid < OrderOpenPrice() + (trailStartsAtProfit / factor) )
            return;
            
          if (Bid >= sl + (TrailingStopPips / factor) )//George
          {
             NewStop = NormalizeDouble(Bid - (TrailingStopPips / factor), Digits); //FourXXX
             if (HiddenPips > 0) ObjectMove(LineName, 0, Time[0], NewStop);
             if (NewStop - OrderStopLoss() >= Point) modify = true;//George again. What a guy
          }//if (Bid >= MathMax(sl,OrderOpenPrice()) + (TrailingStopPips / factor) )//George
       }//if (OrderType()==OP_BUY)
       
       if (OrderType()==OP_SELL)
       {
          if (sl > OrderOpenPrice() ) return;//Not at breakeven yet
          // Decrement sl by sl - TrailingStopPips.
          if (CloseEnough(sl, 0) ) sl = MathMin(OrderStopLoss(), OrderOpenPrice());
          if (CloseEnough(sl, 0) ) sl = OrderOpenPrice();
          
          //Check that the market is sufficiently in profit to continue
          if (Bid > OrderOpenPrice() - (trailStartsAtProfit / factor) )
            return;
           
          
          if (Bid <= sl  - (TrailingStopPips / factor))//George
          {
             NewStop = NormalizeDouble(Bid + (TrailingStopPips / factor), Digits); //FourXXXX
             if (HiddenPips > 0) ObjectMove(LineName, 0, Time[0], NewStop);
             if (OrderStopLoss() - NewStop >= Point || OrderStopLoss() == 0) modify = true;//George again. What a guy   
          }//if (Bid <= MathMin(sl, OrderOpenPrice() ) - (TrailingStopPips / factor) )//George
       }//if (OrderType()==OP_SELL)


   //Move 'hard' stop loss whether hidden or not. Don't want to risk losing a breakeven through disconnect.
   if (modify)
   {
      while (IsTradeContextBusy() ) Sleep(100);
      result = ModifyOrder(OrderTicket(), OrderOpenPrice(), NewStop, OrderTakeProfit(), OrderExpiration(), clrNONE, __FUNCTION__, slm);
   }//if (modify)
      
} // End of TrailingStopLoss sub
Author:  SteveHopwood [ Wed Oct 28, 2020 11:58 am ]
Post subject:  Ghostrider

Fourxxxx » Wed Oct 28, 2020 11:47 am wrote:Hope I am not out of line posting this here.

I think that the trailing stop is not working as expected.

These 2 lines adding or subtracting from the current StopLoss rather than the Bid.

3683

Code: Select all

NewStop = NormalizeDouble(sl + (TrailingStopPips / factor), Digits)
3703

Code: Select all

NewStop = NormalizeDouble(sl - (TrailingStopPips / factor), Digits);
With the changes here it seems to be working as intended.

Code: Select all

void TrailingStopLoss(int ticket)
{

   //Security check
   if (!BetterOrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES))
      return;
   
   if (OrderProfit() < 0) return;//Nothing to do
   string LineName = SlPrefix + DoubleToStr(OrderTicket(), 0);
   double sl = ObjectGet(LineName, OBJPROP_PRICE1);
   //if (CloseEnough(sl, 0) ) return;//No line, so nothing to do
   if (CloseEnough(sl, 0) ) sl = OrderStopLoss();
   double NewStop;
   bool modify=false;
   bool result;
   
    if (OrderType()==OP_BUY)
       {
          if (sl < OrderOpenPrice() ) return;//Not at breakeven yet
          // Increment sl by sl + TrailingStopPips.
          if (CloseEnough(sl, 0) ) sl = MathMax(OrderStopLoss(), OrderOpenPrice());
          
          //Check that the market is sufficiently in profit to continue
          if (Bid < OrderOpenPrice() + (trailStartsAtProfit / factor) )
            return;
            
          if (Bid >= sl + (TrailingStopPips / factor) )//George
          {
             NewStop = NormalizeDouble(Bid - (TrailingStopPips / factor), Digits); //FourXXX
             if (HiddenPips > 0) ObjectMove(LineName, 0, Time[0], NewStop);
             if (NewStop - OrderStopLoss() >= Point) modify = true;//George again. What a guy
          }//if (Bid >= MathMax(sl,OrderOpenPrice()) + (TrailingStopPips / factor) )//George
       }//if (OrderType()==OP_BUY)
       
       if (OrderType()==OP_SELL)
       {
          if (sl > OrderOpenPrice() ) return;//Not at breakeven yet
          // Decrement sl by sl - TrailingStopPips.
          if (CloseEnough(sl, 0) ) sl = MathMin(OrderStopLoss(), OrderOpenPrice());
          if (CloseEnough(sl, 0) ) sl = OrderOpenPrice();
          
          //Check that the market is sufficiently in profit to continue
          if (Bid > OrderOpenPrice() - (trailStartsAtProfit / factor) )
            return;
           
          
          if (Bid <= sl  - (TrailingStopPips / factor))//George
          {
             NewStop = NormalizeDouble(Bid + (TrailingStopPips / factor), Digits); //FourXXXX
             if (HiddenPips > 0) ObjectMove(LineName, 0, Time[0], NewStop);
             if (OrderStopLoss() - NewStop >= Point || OrderStopLoss() == 0) modify = true;//George again. What a guy   
          }//if (Bid <= MathMin(sl, OrderOpenPrice() ) - (TrailingStopPips / factor) )//George
       }//if (OrderType()==OP_SELL)


   //Move 'hard' stop loss whether hidden or not. Don't want to risk losing a breakeven through disconnect.
   if (modify)
   {
      while (IsTradeContextBusy() ) Sleep(100);
      result = ModifyOrder(OrderTicket(), OrderOpenPrice(), NewStop, OrderTakeProfit(), OrderExpiration(), clrNONE, __FUNCTION__, slm);
   }//if (modify)
      
} // End of TrailingStopLoss sub
Thanks. :clap: :clap: :clap: :clap: :clap: :clap: :clap: :clap: :clap: :clap:

I could not see how the code would work properly and meant to sort it out, then became involved in another project and forgot. I will make the change and update later. DIYers, just copy the function over the top of the existing one.

:xm: :rocket:
Author:  SteveHopwood [ Wed Oct 28, 2020 3:17 pm ]
Post subject:  Ghostrider

V 1g is in post 1, with FourXXXX's fix for the faulty trailing stop. I must have been on drugs when I coded my version.

Easy DIY fix. Do a search for:
NewStop = NormalizeDouble(sl + (TrailingStopPips / factor), Digits);

Replace it with:
//Thanks to FourXXXX for sorting out this next line of code
NewStop = NormalizeDouble(Bid - (TrailingStopPips / factor), Digits); //FourXXX

Then do a search for:
NewStop = NormalizeDouble(sl - (TrailingStopPips / factor), Digits);

Replace it with:
//Thanks to FourXXXX for sorting out this next line of code
NewStop = NormalizeDouble(Bid + (TrailingStopPips / factor), Digits); //FourXXXX

:xm: :rocket:
Author:  SteveHopwood [ Thu Oct 29, 2020 4:31 pm ]
Post subject:  Ghostrider

V 1his in post 1.

I am working with c1borg on a more accurate representation of Ghostrider's trading method. Referring back to this version I noticed that I had not included the StopLossDistancePips value into the stop loss calculation.

Easy DIY for those of you who prefer this:
Do a search for:
stop = CalculateStopLoss(OP_BUY, rectangleLow[arrayIndex]);

Replace it with:
stop = CalculateStopLoss(OP_BUY, rectangleLow[arrayIndex] - (StopLossDistance / factor) );

Then do a search for:
stop = CalculateStopLoss(OP_SELL, rectangleHigh[arrayIndex]);

Replace it with:
stop = CalculateStopLoss(OP_SELL, rectangleHigh[arrayIndex] + (StopLossDistance / factor) );

Brief update on progress. The H4 demo is a small loser. The H1 demo is in the green by $240 - 0.2 lots on a $20,000 deposit. There is an H1 demo with all the latest stuff thrown at it, balance in loss but equity in profit thanks to a massive AU sell that is currently at +125. Mind, I had forgotten to set the jumping stop so it probably would not have gotten so far.

That last one should maybe give us pause for thought. Maybe we should be allowing the trades a longer run? There are not many of them, after all.

:xm: :rocket:
Author:  wallywonka [ Thu Oct 29, 2020 10:19 pm ]
Post subject:  Ghostrider

Agree on this Steve, had a demo run last week and it had no stop loss settings and it did quite well.. it would have stopped out a few times. I do like the stop loss just outside the trading zone though as some trades do continue through the support/resistance zones so it is good to get out of those trades.
Author:  Pipstubborn [ Fri Oct 30, 2020 2:32 pm ]
Post subject:  Ghostrider

Hi Wally,

Not sure what I'm doing wrong Just got one trade in the whole week, AUDUSD (in profit).
Would you mind to share your PRESET FILE with the new version V1 h?

Thanks in advance,
Pipstubborn
Author:  SteveHopwood [ Fri Oct 30, 2020 4:47 pm ]
Post subject:  Ghostrider

Pipstubborn » Fri Oct 30, 2020 2:32 pm wrote:Hi Wally,

Not sure what I'm doing wrong Just got one trade in the whole week, AUDUSD (in profit).
Would you mind to share your PRESET FILE with the new version V1 h?

Thanks in advance,
Pipstubborn
This one is not a trading tart. If the ducks don't line up, they don't line up.

:xm: :rocket:
Author:  SteveHopwood [ Sun Nov 01, 2020 11:22 am ]
Post subject:  Ghostrider

V 1i is in post 1, responding to a request from Wally that I include the option to send stop orders following a trade trigger. The inputs are immediately under the 'General Inputs' section and should be obvious but details in the user guide if not.

A DIY job should not be too difficult. Go to the space in between the support/resistance variables and the trading time frame inputs and insert the inputs for the trade types:

Code: Select all

extern string  sep17="================================================================";
extern string  ttp="---- Trade Types ----";
extern bool    SendImmediateMarketOrder=true;
extern bool    SendStopOrder=false;
extern int     DistanceFromMarketPips=10;//No of pips away from market to set the stop
////////////////////////////////////////////////////////////////////////////////////////
double         distanceFromMarket=0;
////////////////////////////////////////////////////////////////////////////////////////
do a search for: trailStartsAtProfit = TrailStartsAtProfitPips;
Add this to the list
distanceFromMarket = DistanceFromMarketPips;

Do a search for: type=OP_BUY;

Replace the existing code block with:

Code: Select all

      if (SendImmediateMarketOrder)
      {
         type=OP_BUY;
         stype = " Buy ";
         price = Ask;
      }//if (SendImmediateMarketOrder)
      else
      {
         type=OP_BUYSTOP;
         stype = " Buy stop ";
         price = NormalizeDouble(Ask + (distanceFromMarket / factor), Digits);
      }//else
Do a search for: Do a search for: type=OP_SELL;
Replace that block of code with:

Code: Select all

      if (SendImmediateMarketOrder)
      {
         type=OP_SELL;
         stype = " Sell ";
         price = Bid;
      }//if (SendImmediateMarketOrder)
      else
      {
         type=OP_SELLSTOP;
         stype = " Sell stop ";
         price = NormalizeDouble(Bid - (distanceFromMarket / factor), Digits);
      }//else
  

:xm: :rocket:
Author:  wallywonka [ Sun Nov 01, 2020 11:33 am ]
Post subject:  Ghostrider

Cheers for adding this in Steve, it would have saved me from a couple of bad trades last week!

:clap: :clap: :clap:
Author:  SteveHopwood [ Sun Nov 01, 2020 12:02 pm ]
Post subject:  Ghostrider

wallywonka » Sun Nov 01, 2020 11:33 am wrote:Cheers for adding this in Steve, it would have saved me from a couple of bad trades last week!

:clap: :clap: :clap:
You are most welcome Wally. You are becoming a most helpful member of SHF. :clap: :clap: :clap: :clap: :clap:

:xm: :rocket:
All times are UTC Page 5 of 12