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

Gday Mark 2
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=917
Page 22 of 30
Author:  VirtualFM [ Wed Feb 27, 2013 12:57 am ]
Post subject:  Re: Gday Mark 2

SteveHopwood wrote:At the very least, this post has given me the chance to 'think out loud'.

:D
Those are great moments! Keep thinking! :-)
Author:  fx800 [ Fri Mar 01, 2013 9:44 pm ]
Post subject:  Re: Gday Mark 2

Hi Steve,

For your Gday MK 2 EA, I would like to try using a pending order to buy when a candle cross above the stoch 20, xxx pips above the high of the candle that crosses the stoch 20 + spread.

Is it correct to use the following code

//Long
if (SendLong)
{
type = OP_BUYSTOP;

if (!BuyOpen)
{
price = High[1] + (BufferPips / factor) + (spread / factor);

}//if (!BuyOpen)

}//if (SendLong)


and for sell

//Short
if (SendShort)
{
type = OP_SELLSTOP;

if (!SellOpen)
{
price = Low[1] - (BufferPips / factor) - (spread / factor);

}//if (!SellOpen)

}//if (SendShort)

I have been testing this on demo, and found that the EA places a trade as soon as the stoch crosses the 20/80 line. Not sure why.

Many thanks.

peter
Author:  SteveHopwood [ Fri Mar 01, 2013 10:05 pm ]
Post subject:  Re: Gday Mark 2

fx8000 wrote:Hi Steve,

For your Gday MK 2 EA, I would like to try using a pending order to buy when a candle cross above the stoch 20, xxx pips above the high of the candle that crosses the stoch 20 + spread.

Is it correct to use the following code

//Long
if (SendLong)
{
type = OP_BUYSTOP;

if (!BuyOpen)
{
price = High[1] + (BufferPips / factor) + (spread / factor);

}//if (!BuyOpen)

}//if (SendLong)


and for sell

//Short
if (SendShort)
{
type = OP_SELLSTOP;

if (!SellOpen)
{
price = Low[1] - (BufferPips / factor) - (spread / factor);

}//if (!SellOpen)

}//if (SendShort)

Many thanks.

peter
A tip for you Peter. Next time you post code, enclose it within a thingy - this preserves the formatting and makes it easier to read.

Assuming that you have calculated
double spread = (Ask - Bid) * factor

then your code should work. Try it and see.

:D

Here is how code looks when enclosed within

Code: Select all

   //Long 
   if (SendLong)
   {
       
      stype = " Buy ";
      
      if (!SendAlertNotTrade)
      {
         //Got this far, so there is going to be a trade send of some sort. Setting up price here makes
         //this code most easily adaptable to easy alteration
         price = Ask;//Change this to whatever the price needs to be
         
         
         take = CalculateTakeProfit(OP_BUY);
         
         stop = CalculateStopLoss(OP_BUY);
         
         
         //Lot size calculated by risk
         if (RiskPercent > 0) SendLots = CalculateLotSize(price, NormalizeDouble(stop, Digits) );

         type = OP_BUY;
         
      }//if (!SendAlertNotTrade)
      
      SendTrade = true;
      
}//if (SendLong)
Doesn't do anything with wrapped comments, but the rest is much more readable.

:D
Author:  fx800 [ Fri Mar 01, 2013 10:24 pm ]
Post subject:  Re: Gday Mark 2

Thank you very much, Steve. Sorry didn't know how to use "code : SELLECT ALL" before. This is how the code should look like.

Code: Select all

    //Long 
   if (SendLong)
   {                
       type = OP_BUYSTOP;      
      //price = Ask;//Change this to whatever the price needs to be
      
      if (!BuyOpen)
      {
         price = High[1] + (BufferPips / factor) + (spread / factor);

      }//if (!BuyOpen)
           
             
      if (!SendAlertNotTrade)
      {         
         take = CalculateTakeProfit(OP_BUY);
         
         stop = CalculateStopLoss(OP_BUY);
         
         
         //Lot size calculated by risk
         if (RiskPercent > 0) SendLots = CalculateLotSize(price, NormalizeDouble(stop, Digits) );

         type = OP_BUY;
         
      }//if (!SendAlertNotTrade)
      
      SendTrade = true;
      
   }//if (SendLong)
   
   
   //Short
   if (SendShort)
   {
      type = OP_SELLSTOP;
      //price = Bid;//Change this to whatever the price needs to be

      if (!SellOpen)
      {
         price = Low[1] - (BufferPips / factor) - (spread / factor);

      }//if (!SellOpen)
      
                
      if (!SendAlertNotTrade)
      {
         
         take = CalculateTakeProfit(OP_SELL);
         
         stop = CalculateStopLoss(OP_SELL);
         
         
         //Lot size calculated by risk
         if (RiskPercent > 0) SendLots = CalculateLotSize(NormalizeDouble(stop, Digits), price);
         
         type = OP_SELL;
      }//if (!SendAlertNotTrade)
         
      SendTrade = true;      
   
      
   }//if (SendShort)
My mistake was using

Code: Select all

   double spread = Ask - Bid;
, which I obtained from your Pending order script which you very kindly wrote for one of our members some time ago.

I thought

Code: Select all

(spread / factor)
already took account of the factor bit.

I shall try the "double spread =(Ask - Bid)*factor " next week.

Cheers,
peter
Author:  SteveHopwood [ Fri Mar 01, 2013 10:41 pm ]
Post subject:  Re: Gday Mark 2

fx8000 wrote:Thank you very much, Steve. Sorry didn't know how to use "code : SELLECT ALL" before.

My mistake was using " double spread = Ask - Bid", which I obtained from your Pending order script which you very kindly wrote for one of our members some time ago.

I shall try the "double spread =(Ask - Bid)*factor " next week.

Cheers,
peter
It depends what you want to do. I declare spread purely locally, in DisplayUserFeedback() and IsTradingAllowed()

It may be easier to simply declare spread as a programme-wide variable and read it at the top of start(). I do what I do because I do what I do and it works for me, not because I have some glorious insight into the use of the spread.

:D
Author:  fx800 [ Fri Mar 01, 2013 10:59 pm ]
Post subject:  Re: Gday Mark 2

SteveHopwood wrote:
fx8000 wrote:Thank you very much, Steve. Sorry didn't know how to use "code : SELLECT ALL" before.

My mistake was using " double spread = Ask - Bid", which I obtained from your Pending order script which you very kindly wrote for one of our members some time ago.

I shall try the "double spread =(Ask - Bid)*factor " next week.

Cheers,
peter
It depends what you want to do. I declare spread purely locally, in DisplayUserFeedback() and IsTradingAllowed()

It may be easier to simply declare spread as a programme-wide variable and read it at the top of start(). I do what I do because I do what I do and it works for me, not because I have some glorious insight into the use of the spread.

:D
I have put the "double spread" in the wrong place.

I have now moved it to top of Start() as you suggested, like so

Code: Select all

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
{
//----

   double spread = (Ask-Bid)*factor;
   
   //Create a flashing comment if there has been a rogue trade
   if (RobotSuspended) 
   {
      while (RobotSuspended)
      {
         Comment(NL, Gap, "****************** ROBOT SUSPENDED. POSSIBLE ROGUE TRADING ACTIVITY. REMOVE THIE EA IMMEDIATELY ****************** ");
         Sleep(2000);
         Comment("");
         Sleep(1000);
       }//while (RobotSuspended)           
      return;
   }//if (RobotSuspended) 
   
    //If HG is sleeping after a trade closure, is it time to awake?
   if (SafetyViolation) TooClose();
   if (SafetyViolation)//TooClose() sets SafetyViolation
   {
      DisplayUserFeedback();
      return;
   }//if (SafetyViolation) 
Author:  SteveHopwood [ Fri Mar 01, 2013 11:15 pm ]
Post subject:  Re: Gday Mark 2

You still have spread declared as a local variable. It cannot be used throughout your programme unless you pass it to functions as a parameter.

Sorry, but I am tired now and have done the best I can to help. It is up to you to sort things out for yourself now. You will - I did when I started.

:D
fx8000 wrote:
SteveHopwood wrote:
fx8000 wrote:Thank you very much, Steve. Sorry didn't know how to use "code : SELLECT ALL" before.

My mistake was using " double spread = Ask - Bid", which I obtained from your Pending order script which you very kindly wrote for one of our members some time ago.

I shall try the "double spread =(Ask - Bid)*factor " next week.

Cheers,
peter
It depends what you want to do. I declare spread purely locally, in DisplayUserFeedback() and IsTradingAllowed()

It may be easier to simply declare spread as a programme-wide variable and read it at the top of start(). I do what I do because I do what I do and it works for me, not because I have some glorious insight into the use of the spread.

:D
I have put the "double = spread" in the wrong place.

I have now moved it to top of Start() as you suggested, like so

Code: Select all

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
{
//----

   double spread = (Ask-Bid)*factor;
   
   //Create a flashing comment if there has been a rogue trade
   if (RobotSuspended) 
   {
      while (RobotSuspended)
      {
         Comment(NL, Gap, "****************** ROBOT SUSPENDED. POSSIBLE ROGUE TRADING ACTIVITY. REMOVE THIE EA IMMEDIATELY ****************** ");
         Sleep(2000);
         Comment("");
         Sleep(1000);
       }//while (RobotSuspended)           
      return;
   }//if (RobotSuspended) 
   
    //If HG is sleeping after a trade closure, is it time to awake?
   if (SafetyViolation) TooClose();
   if (SafetyViolation)//TooClose() sets SafetyViolation
   {
      DisplayUserFeedback();
      return;
   }//if (SafetyViolation) 
Author:  fx800 [ Fri Mar 01, 2013 11:32 pm ]
Post subject:  Re: Gday Mark 2

Thank you, Steve. I am sure I will figure things out myself.

Thanks for your help, and have a nice week end.

peter
Author:  fx800 [ Sun Mar 03, 2013 11:48 am ]
Post subject:  Re: Gday Mark 2

fx8000 wrote:Thank you, Steve. I am sure I will figure things out myself.

Thanks for your help, and have a nice week end.

peter

I have solved the problem by adding/subtracting (Ask - Bid) from price, instead of having to declare double spread = (Ask - Bid) * factor again.

Will see if this works tomorrow.

peter
Author:  SteveHopwood [ Sun Mar 03, 2013 12:20 pm ]
Post subject:  Re: Gday Mark 2

fx8000 wrote:
fx8000 wrote:Thank you, Steve. I am sure I will figure things out myself.

Thanks for your help, and have a nice week end.

peter

I have solved the problem by adding/subtracting (Ask - Bid) from price, instead of having to declare double spread = (Ask - Bid) * factor again.

Will see if this works tomorrow.

peter
That is a neat idea - I never thought of that.

:D
All times are UTC Page 22 of 30