Indicator Request

MPTM's new home
Post Reply
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.

Indicator Request

Post by SteveHopwood »

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:
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.
User avatar
Reaper
Trader
Posts: 476
Joined: Sat Feb 09, 2013 12:07 am
Location: UK

Indicator Request

Post by Reaper »

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
.
User avatar
Reaper
Trader
Posts: 476
Joined: Sat Feb 09, 2013 12:07 am
Location: UK

Indicator Request

Post by Reaper »

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.
.
User avatar
Reaper
Trader
Posts: 476
Joined: Sat Feb 09, 2013 12:07 am
Location: UK

Indicator Request

Post by Reaper »

Will just forward test and note any errors during. :!!:
.
User avatar
Reaper
Trader
Posts: 476
Joined: Sat Feb 09, 2013 12:07 am
Location: UK

Indicator Request

Post by Reaper »

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?
.
User avatar
Reaper
Trader
Posts: 476
Joined: Sat Feb 09, 2013 12:07 am
Location: UK

Indicator Request

Post by Reaper »

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?
.
AnotherBrian

Indicator Request

Post by AnotherBrian »

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.
User avatar
milanese
TechAdmin
Posts: 3293
Joined: Wed Jan 09, 2013 9:02 am
Location: btr rdx, r8 +

Indicator Request

Post by milanese »

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
Global Prime is the official SHF broker :yahoo:
Searching for Servers and Workstations with individual configuration?
Just PM
:smile: Click here to go to the BoardKnowledgeBase
NOTE: Cookies and JavaScript are required for the using the board, with full functionality
User avatar
Reaper
Trader
Posts: 476
Joined: Sat Feb 09, 2013 12:07 am
Location: UK

Indicator Request

Post by Reaper »

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() .
.
User avatar
Reaper
Trader
Posts: 476
Joined: Sat Feb 09, 2013 12:07 am
Location: UK

Indicator Request

Post by Reaper »

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.
.
Post Reply

Return to “Utilities Indicators and Scripts”