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

Indicator Request
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=4019
Page 5 of 7
Author:  SteveHopwood [ Sun Jan 11, 2015 10:47 pm ]
Post subject:  Indicator Request

Angat » Sun Jan 11, 2015 5:12 pm wrote:
If anyone is wondering, I had another look in the HA indicator code and just realised what it meant.

Code: Select all

      if(open[0]<close[0])
        {
         ExtLowHighBuffer[0]=low[0];
         ExtHighLowBuffer[0]=high[0];
        }
      else
        {
         ExtLowHighBuffer[0]=high[0];
         ExtHighLowBuffer[0]=low[0];
        }

     
Damn Heiken Ashi, such a pretty indicator but so weirdly coded. :P
FWIW, I automatically refuse to code EA's the moment the commissioner mentions HA. It is a total abortion of a so-called indicator and madness awaits anybody daft enough to get involved with it. Guess how I know?

Do feel free to ignore my advice, but you will be sorry if you do so. Apart from the impossibility of dragging anything useful from this most clueless of appalling crap custom abortions, on the chart it does appear to insist that the market is going one way whilst it is actually hurtling 180% in the opposite direction.

Again, only my opinion, but it is this: only an idiot involves her/his/itself with this appalling piece of rubbish.

:xm:
Author:  Reaper [ Tue Jan 13, 2015 12:16 am ]
Post subject:  Indicator Request

Steve you do not lie.

It is proving a lot more of a bitch to code than if it was just with regular candles. However my strategy for the last few months was with HA. HA makes a lot easier to recognise what I was looking for specifically.

My first attempt at the EA is nearly ready. There's a lot more signals I can code into it. But I'm just going to get this one version running on my old laptop and see how it fairs.

I've been checking out the latest HGI indi, its pretty slick. I may even try code an EA with that and my strategy, I think it would compliment well.

Keep on using my new found mql4 abilities. :P
Author:  Reaper [ Tue Jan 13, 2015 11:58 am ]
Post subject:  Indicator Request

Code: Select all

// Sets Trailing Stop

for (int i=OrdersTotal()-1; i>= 0; i--)

   {
   
     if(OrderSelect(i, SELECT_BY_POS,MODE_TRADES))
      {

  if((OrderType() <= OP_SELL) && (OrderSymbol() == Symbol()) )
         {
         if(OrderType() == OP_BUY)
            {
            if(UseTrailingStop)
               {
               if((Bid-OrderOpenPrice()) > (Point*TrailingStop))
                  {
                  if((OrderStopLoss()) < (Bid-Point*TrailingStop))
                     {
                    if(OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen))
                     Print ("Trailing Stop Set Successfully"); else Print("Trailing Stop Not Set");
                     }
                  } 
               }                    
             }

            if(OrderType() == OP_SELL)
               {
               if(UseTrailingStop)
                  {
                  if(OrderOpenPrice()-Ask>Point*TrailingStop)
                     {
                     if(OrderStopLoss()>Ask+Point*TrailingStop)
                        {
                    if(OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen))
                     Print ("Trailing Stop Set Successfully"); else Print("Trailing Stop Not Set");             
                        }
                     }     
                  }
                }
             }

}
}
I'm not 100% sure if the trailing stop is functioning correctly. It seems okay sometimes and once or twice perhaps not. It could be backtest numbers throwing me off. Anyway, what I would like is for someone to confirm my use of ASK and BID in the above code? Are they the right way round? And can anyone see any obvious errors? Or is all okay?


I've looked at Steve's shell at his TS function. It's quite different and I may update my code to that eventually but right now I would like to just get what I have working correctly if its not already.

Cheers.
Author:  Reaper [ Tue Jan 13, 2015 3:34 pm ]
Post subject:  Indicator Request

Will just forward test and note any errors during. :!!:
Author:  Reaper [ Thu Jan 15, 2015 9:05 pm ]
Post subject:  Indicator Request

Code: Select all

if(OrderSend(Symbol(),OP_SELL,Lots,NormalizeDouble(Bid,Digits),Slippage*pips2points,NormalizeDouble(Bid+StopLoss*pips2dbl,Digits),NormalizeDouble(Bid-TakeProfit*pips2dbl,Digits), "Go Short",16843,0,Red))
Do I need to use normalizedouble here?
Author:  Reaper [ Sat Jan 17, 2015 2:43 pm ]
Post subject:  Indicator Request

I'm currently trying to move my working EA into Steve's bare bones shell.

I had all my signal variables within the int start() in my old ea. There were a lot of them as I was predefining sets of Heiken Ashi Candles.

I was hoping I can move all my signal variables to the top under the other EA variables. But what I'm finding is I cant call them from within functions like "LookForTradingOpportunities();"

Now if I were to move them all down to within the above function, I'm sure it would work, but is there a way to keep them up the top and still be able to call them from within functions?
Author:  AnotherBrian [ Sat Jan 17, 2015 4:33 pm ]
Post subject:  Indicator Request

Variables that are initialise outside of all functions, including start(), are accessible from all functions. If you initialise inside start(), then only start() will see them.
Also - globalevariables can be used, but thats more for communicating between charts.

from a web [age, edited to make more sense

Global Variable

A global variable is a variable that can be accessed in multiple functions. This means that wherever you are in the program you can use that variable: get its current value or set its value to something else. Global variables are created using the initialize global name to block found in the Variables drawer.

Local Variable

A local variable is a variable that is declared within a function or it is an argument passed into a function. This means that you can only access these variables in that specific function where they are declared or passed in as an argument.

Here is an example

Code: Select all

//start of code
bool var;

start(){
bool small;
some code;
//we can access variables 'small' and 'var'
}

myfunction(){
bool myvariable;
somecode;
//we can access variables 'var' and myvariable
}
Hope this is what you were asking? I know it took me a while to figure this out when I started.
Author:  milanese [ Sat Jan 17, 2015 6:04 pm ]
Post subject:  Indicator Request

Angat » Sat Jan 17, 2015 2:43 pm wrote:I'm currently trying to move my working EA into Steve's bare bones shell.

I had all my signal variables within the int start() in my old ea. There were a lot of them as I was predefining sets of Heiken Ashi Candles.

I was hoping I can move all my signal variables to the top under the other EA variables. But what I'm finding is I cant call them from within functions like "LookForTradingOpportunities();"

Now if I were to move them all down to within the above function, I'm sure it would work, but is there a way to keep them up the top and still be able to call them from within functions?
Steve's shell uses a good structure to understand what all functions do, it is coded, because so it is easy adaptable to nearly all requested strategies.
In LookForTradingOpportunities() is all that is needed for make the trading decissions for opening positions, if the strategy useses indicators, the ReadIndicators() part is the modul for getting the indicator values. I will give you an example how to handle his:

Code: Select all

//start of your code 
// here you put all your global variable stuff
double yourIndivalue_1=0.0;
double yourIndivalue_2=0.0;
bool doLong=false;
bool doShort=false;

//Here you get the indicator values

 void ReadIndicators() {
//fictiv iCustom call
yourIndivalue_1=iCustom(Symbol(), 0, IndiName, MaMetod, MaPeriod, MaMetod2, MaPeriod2, 4, shift);
yourIndivalue_2=iCustom(Symbol(), 0, IndiName, MaMetod, MaPeriod, MaMetod2, MaPeriod2, 2, shift);

}
//ok now we look for possibilities to open a position

void LookForTradingOpportunities() {
doLong=false;//resetting 
doShort=false;// resetting
ReadIndicators();//we need to get the latest indi_values
if (yourIndivalue_1 > yourIndivalue_2) {
doLong=true;
}
else if (yourIndivalue_1 < yourIndivalue_2) {
doShort=true;
}
}



Hope this helps somewhat..


Cheers :)

Tommaso
Author:  Reaper [ Sat Jan 17, 2015 6:10 pm ]
Post subject:  Indicator Request

AnotherBrian » Sat Jan 17, 2015 4:33 pm wrote:Variables that are initialise outside of all functions, including start(), are accessible from all functions. If you initialise inside start(), then only start() will see them.
Also - globalevariables can be used, but thats more for communicating between charts.

from a web [age, edited to make more sense

Global Variable

A global variable is a variable that can be accessed in multiple functions. This means that wherever you are in the program you can use that variable: get its current value or set its value to something else. Global variables are created using the initialize global name to block found in the Variables drawer.

Local Variable

A local variable is a variable that is declared within a function or it is an argument passed into a function. This means that you can only access these variables in that specific function where they are declared or passed in as an argument.

Here is an example

Code: Select all

//start of code
bool var;

start(){
bool small;
some code;
//we can access variables 'small' and 'var'
}

myfunction(){
bool myvariable;
somecode;
//we can access variables 'var' and myvariable
}
Hope this is what you were asking? I know it took me a while to figure this out when I started.
Yes thanks, this is basically what I'm asking but for some unknown reason, I have global variables that cant be access within functions.

For example I have

Code: Select all

bool LineDetectABZERO = ((ObjectFind(0,"AlphaLine_0")==0) || (ObjectFind(0,"BetaLine_0")==0));
as a global variable.

Then in LookForTradingOpportunities() function I want to say

Code: Select all

If(LineDetectABZERO) 
 SendShort = true;
But apparently this doesn't work. But does work if I move "bool LineDetectABZERO..." to within LookForTradingOpportunities() .
Author:  Reaper [ Sat Jan 17, 2015 6:11 pm ]
Post subject:  Indicator Request

milanese » Sat Jan 17, 2015 6:04 pm wrote:
Angat » Sat Jan 17, 2015 2:43 pm wrote:I'm currently trying to move my working EA into Steve's bare bones shell.

I had all my signal variables within the int start() in my old ea. There were a lot of them as I was predefining sets of Heiken Ashi Candles.

I was hoping I can move all my signal variables to the top under the other EA variables. But what I'm finding is I cant call them from within functions like "LookForTradingOpportunities();"

Now if I were to move them all down to within the above function, I'm sure it would work, but is there a way to keep them up the top and still be able to call them from within functions?
Steve's shell uses a good structure to understand what all functions do, it is coded, because so it is easy adaptable to nearly all requested strategies.
In LookForTradingOpportunities() is all that is needed for make the trading decissions for opening positions, if the strategy useses indicators, the ReadIndicators() part is the modul for getting the indicator values. I will give you an example how to handle his:

Code: Select all

//start of your code 
// here you put all your global variable stuff
double yourIndivalue_1=0.0;
double yourIndivalue_2=0.0;
bool doLong=false;
bool doShort=false;

//Here you get the indicator values

 void ReadIndicators() {
//fictiv iCustom call
yourIndivalue_1=iCustom(Symbol(), 0, IndiName, MaMetod, MaPeriod, MaMetod2, MaPeriod2, 4, shift);
yourIndivalue_2=iCustom(Symbol(), 0, IndiName, MaMetod, MaPeriod, MaMetod2, MaPeriod2, 2, shift);

}
//ok now we look for possibilities to open a position

void LookForTradingOpportunities() {
doLong=false;//resetting 
doShort=false;// resetting
ReadIndicators();//we need to get the latest indi_values
if (yourIndivalue_1 > yourIndivalue_2) {
doLong=true;
}
else if (yourIndivalue_1 < yourIndivalue_2) {
doShort=true;
}
}



Hope this helps somewhat..


Cheers :)

Tommaso
Thanks Tommaso. I'm just trying to figure out why a global variable isn't being recognised, but if I were to move the same variable instead a function it works.
All times are UTC Page 5 of 7