Timeframe as a variable, which declaration type? - mql4

I am working on a MQL4 expert advisor. This advisor uses 2 separate
timeframes for its signals and entries/exits. Up until now I have used an "sinput" to allow the user to choose the desired timeframe for the higher timeframe indicators.
I would like to remove the option, and have the optimized pairs set automatically in my code. I am attempting to initiate a variable "IndicatorTF", and then later assign it a value of the desired timeframe.
Every other portion of my code runs just fine, however programmatically setting and changing timeframes is new to me.
If I try to initialize the variable "IndicatorHTF" globally and then actually set the value in "On Init" I get an error stating that I cannot change a constant. If, however, I set the "IndicatorHTF" variable directly in "On Init", just before it is actually used, I get a declaration error as I cant seem to find the correct type.
I realize its not a bool, int, double, or string, but I have no Idea what I should be using as a type.
What ive tried:
1)
//Globally
ENUM_TIMEFRAMES IndicatorHTF; //with sinput,bool,string,etc
int OnInit()
{
if(Period()==PERIOD_M1){resolution=PERIOD_M5;}
}
2)
int OnInit()
{
ENUM_TIMEFRAMES IndicatorHTF; //with sinput,bool,string,etc
if(Period()==PERIOD_M1){resolution=PERIOD_M5;}
}

Fixed the issue, it was simply a placement issue. By setting
if(Period()==PERIOD_M1){IndicatorHTF=PERIOD_M5;}
actually within my trade logic that used IndicatorHTF it was able to read and set the values correctly :)

Related

Why can we not change the variable value if initialises at the time of declaration?

I am learning dart and this behavior of dart is annoying me
var a=10;
a="John"; //it generates an error, because a has integer data-type and we can't assign
//string or the value of any other data type because we have assigned an
//integer value
but at the same time, dart allows us to write
var a;
a=10;
a="John";
print (a) //it displays John
it means that we can't assign the value of any other data type when a variable initializes at the time of declaration but we can assign the value of any other data type if the variable declares in one line and initializes at the second line. Why does dart work in this way?
The var keyword is used to let Dart automatically assign a type for the variable based on the value you are using to initialize the variable.
If you use var without providing any initial value, the type of your variable are automatically being assign to dynamic which allows any type of object to be assigned to the variable. But it also means your program are much less type safe since the analyzer can no longer help you with what type the variable are going to return and what types are allowed when setting the variable.
So in your first example, a is being assigned the type int since you provide 10 as the initial value. It is therefore a compile error when you are trying to set a String as the new value of your int variable.
In your second example, a is going to be dynamic since you are not providing any initial value. So it is not a problem to first give it 10 and later 'John' since dynamic allow us to use any type. But that also means that when we try to use a in our program, Dart cannot make any guarantees about what type of object you are going to get so errors will first be identified at runtime.
That's because var means dart will assign the type of variable itself.
In first case, the dart assigned variable a as int type because it was given a value during initialisation.
But in second case, the dart assigned variable a as dynamic and that's why you can assign it either a string or int later on.

Modifying the operating frequency (for 802.11ac) on ns-3

I am attempting to change the operating frequency to 300MHz (to simulate the working of 802.11af) but retain the overall PHY layer configuration of 802.11ac.
I have gone through earlier posts and realized that the SetFrequency() function (in the class YansWifiPhy) can be employed. However, when I implement the following statement ('wifi' is an object of the class WifiHelper)-
NetDeviceContainer staDevices = wifi.Install (phy, mac, wifiStaNodes);
I get an error since the object 'phy' is required to be of YansWifiPhyHelper datatype, not YansWifiPhy. However, I can't seem to change the frequency using the YansWifiPhyHelper class. How do I resolve this problem?
As you can see YansWifiPhy is a child class of WifiPhy. The typeId of WifiPhy has Frequency as an attribute. You can set this attribute using any to of the following way:
You can change the default value of ns3::WifiPhy::Frequency using the Config::SetDefault function. The documentation for the same can be found here.
Secondly you can use the Set function of YansWifiPhyHelper to set any attribute of YansWifiPhy (WifiPhy). You can find an example of this here. The only difference from the link will be that you need to change the attribute name to Frequency and change the value accordingly.
Please, let me know in case of any doubts or any of these don't work for you.

What is the syntax for implicit cast operator in dart?

I would like to cast instances of my custom class A to int. What is the syntax of the implicit cast operator? (I thought I remembered that there is such a feature but I can't find it on the web)
int a = (new A());
You can also use as to help tell the tools "no, really, treat this object as this type".
A good example of this is when you have to deal with dart:html's querySelector() function.
FormElement form = querySelector('#sign-up') as FormElement;
In the above, the object returned by querySelector('#sign-up') is checked that it is really an instance of FormElement.
Learn more at https://www.dartlang.org/docs/dart-up-and-running/ch02.html#operators
Type annotations are not allowed to affect behavior in Dart. If you're not running in checked mode, then this:
int a = new A();
will work the same as this:
var a = new A();
at run-time. In other words, when not in checked mode, you're welcome to store your A in a variable annotated as an int, but no actual conversion takes place.
If you are running in checked mode, the first form will give you a runtime exception.
I'm not sure, but I think what you're asking for is a way to define a conversion between your class A and int that will happen automatically when "cast" to an int. No such thing exists, to my knowledge. You should simply define a method to do so. For example:
int a = new A().to_i();

Why is there a Value property on the Option type in F#?

According to the documentation for Option.Value<'T>:
Get the value of a Some option. A NullReferenceException is raised if
the option is None.
and
This function is for use by compiled F# code and should not be used
directly.
Does the last sentence imply that it's due to interop? What's the use case if so?
Otherwise it seems very strange since the whole point of the Option type is to make the possibility of undefined values explicit and encourage handling of them, which easily can be circumvented:
let none : int option = None
let value = none.Value
I imagine it is there so that
match v with
|Some(t) -> t
works - without that Value property, you wouldn't be able to get the t with any functions which are available to F# code (Note there are some DU properties which are not accesible from F# which are an alternative here). There may also be some very minor speed benifits if you know that the option is Some as you don't check it if you use value directly

How to use Property Sets on Snippets in Revolution

If I understand MODX Revolution correctly, I should be able to make a Property Set (Tools -> Property Sets) and apply it to an element as default properties. See rtfm.modx.com.
I have created a Property Set - 'tvsEnabled' - with the following values:
includeTVs: 1
tvPrefix: (empty string)
processTVs: 1
And then I call the following Snippet:
[[getResources#tvsEnabled? &parents=`8` &tpl=`TplArticle`]]
This returns nothing...
Firstly, please provide the code for TplArticle tpl, as there may be error in that tpl as well. The above code is perfectly correct.
Secondly, the tvPrefix parameter should be set properly. If you put an empty string, its no harm. But, try not overriding its default value. Now, if you have put an empty string, your tpl should access template variables according to the tvPrefix that you have provided, for e.g., [[+name]]. If you don't override its default value, you have to access template variables with the +tv. prefix, for e.g., [[+tv.name]].
If this doesn't work out, please do elaborate on the total task at hand and all the pieces of codes in relation to that, which you have written.

Resources