Gday Mark 2

Post Reply
VirtualFM
Trader
Posts: 84
Joined: Sat Apr 28, 2012 3:45 am

Re: Gday Mark 2

Post by VirtualFM »

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

:D
Those are great moments! Keep thinking! :-)
fx800
Trader
Posts: 1334
Joined: Sun Dec 04, 2011 4:11 am

Re: Gday Mark 2

Post by fx800 »

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
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: Gday Mark 2

Post by SteveHopwood »

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
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
fx800
Trader
Posts: 1334
Joined: Sun Dec 04, 2011 4:11 am

Re: Gday Mark 2

Post by fx800 »

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
Last edited by Anonymous on Fri Mar 01, 2013 10:44 pm, edited 1 time in total.
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: Gday Mark 2

Post by SteveHopwood »

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
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
fx800
Trader
Posts: 1334
Joined: Sun Dec 04, 2011 4:11 am

Re: Gday Mark 2

Post by fx800 »

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) 
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: Gday Mark 2

Post by SteveHopwood »

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) 
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
fx800
Trader
Posts: 1334
Joined: Sun Dec 04, 2011 4:11 am

Re: Gday Mark 2

Post by fx800 »

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

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

peter
fx800
Trader
Posts: 1334
Joined: Sun Dec 04, 2011 4:11 am

Re: Gday Mark 2

Post by fx800 »

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
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: Gday Mark 2

Post by SteveHopwood »

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
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
Post Reply

Return to “Automated trading systems”