Use of #$ variables

Hi,

 

I am still a little bemused by the use of #$ varaibles although I have integrated them successfully in other scripts.

This script tries to use #$factor as an adjustable variable but it does not seem to work and the “factor” option does not appear in the adjustable variables when the script is used.

Here is the script;

//This is the 3period exponential MA of the TEI // // #$factor=1; // //TM1 factors TMbar1=4*$factor; TMbar2=10*$factor; TMosc=29*$factor: // TM1=MACD(BAR1=TMbar1, BAR2=TMbar2, OSC=TMbar3, CALC=HLC, STYLE=Exponential); TM2=OFFSET(TM1, OFFSET=2); // TMDirection=IF((TM1-TM2)<0, -1, IF((TM1-TM2)>0,1,0)); // TMTrendDirection=IF(TM1<0,-1,IF(TM1>0,1,0)); // //MA factors MAbars=12*$factor; MAoffset=3*$factor; // M1=MA(BARS=MAbars, STYLE=Exponential); M2=OFFSET(M1, OFFSET=MAoffset); // MomDirection=IF((M1-M2)>0,1,IF((M1-M2)<0,-1,0)); // M3offest=1*$factor M3=OFFSET(M1, OFFSET=M3offset); // MASlope=M1-M3; MADirection=IF(MASlope<0,-1,IF(MASlope>0,1,0)); CloseFactor=If(CLOSE()>M1,1,If(CLOSE()<M1,-1,0)); // MACDbar1=12*$factor; MACDbar2=24*$factor; MACDosc=9*$factor; // MACDFactor=MACD(BAR1=MACDbar1, BAR2=MACDbar2, OSC=MACDosc, CALC=Close, STYLE=Exponential, DEFAULT=Oscillator); MACDPosition=IF(MACDFactor>0,1,IF(MACDFactor<0,-1,0)); // TEInd=(TMDirection+TMTrendDirection+MomDirection+MADirection+CloseFactor+MaCDPosition); // TEIMAadj=MA(TEInd, BARS=3*$factor, STYLE=Exponential, CALC=CLOSE); // TEIMAadj


//This is the 3period exponential MA of the TEI // // #$factor=1; // //TM1 factors TMbar1=4*$factor; TMbar2=10*$factor; TMosc=29*$factor: // TM1=MACD(BAR1=TMbar1, BAR2=TMbar2, OSC=TMbar3, CALC=HLC, STYLE=Exponential); TM2=OFFSET(TM1, OFFSET=2); // TMDirection=IF((TM1-TM2)<0, -1, IF((TM1-TM2)>0,1,0)); // TMTrendDirection=IF(TM1<0,-1,IF(TM1>0,1,0)); // //MA factors MAbars=12*$factor; MAoffset=3*$factor; // M1=MA(BARS=MAbars, STYLE=Exponential); M2=OFFSET(M1, OFFSET=MAoffset); // MomDirection=IF((M1-M2)>0,1,IF((M1-M2)<0,-1,0)); // M3offest=1*$factor M3=OFFSET(M1, OFFSET=M3offset); // MASlope=M1-M3; MADirection=IF(MASlope<0,-1,IF(MASlope>0,1,0)); CloseFactor=If(CLOSE()>M1,1,If(CLOSE()<M1,-1,0)); // MACDbar1=12*$factor; MACDbar2=24*$factor; MACDosc=9*$factor; // MACDFactor=MACD(BAR1=MACDbar1, BAR2=MACDbar2, OSC=MACDosc, CALC=Close, STYLE=Exponential, DEFAULT=Oscillator); MACDPosition=IF(MACDFactor>0,1,IF(MACDFactor<0,-1,0)); // TEInd=(TMDirection+TMTrendDirection+MomDirection+MADirection+CloseFactor+MaCDPosition); // TEIMAadj=MA(TEInd, BARS=3*$factor, STYLE=Exponential, CALC=CLOSE); // TEIMAadj

I have tried to attach the exported script but apparently it is not an allowed file type so I have attached the entire workbook which is only one chart.

cheers

Michael

OANDA-SPI-BIMA-TEIMA-1-time-frame-only.owb (131 KB)

Here is the script again in better form because the forum won’t let me edit my post above.

 

 

//This is the 3period exponential MA of the TEI
//
//sample factor code only
//#$BBBMA=8;
//#$BIMAsma=5;
//BIMAplot=MA(BBBIndex,BARS=$BBBMA, STYLE=Exponential, CALC=Close, TOOLNAME=BIMA);
//
//
#$factor=1;
//
//TM1 factors
TMbar1=4*$factor;
TMbar2=10*$factor;
TMosc=29*$factor:
//
TM1=MACD(BAR1=TMbar1, BAR2=TMbar2, OSC=TMbar3, CALC=HLC, STYLE=Exponential);
TM2=OFFSET(TM1, OFFSET=2);
//
TMDirection=IF((TM1-TM2)<0, -1, IF((TM1-TM2)>0,1,0));
//
TMTrendDirection=IF(TM1<0,-1,IF(TM1>0,1,0));
//
//MA factors
MAbars=12*$factor;
MAoffset=3*$factor;
//
M1=MA(BARS=MAbars, STYLE=Exponential);
M2=OFFSET(M1, OFFSET=MAoffset);
//
MomDirection=IF((M1-M2)>0,1,IF((M1-M2)<0,-1,0));
//
M3offest=1*$factor
M3=OFFSET(M1, OFFSET=M3offset);
//
MASlope=M1-M3;
MADirection=IF(MASlope<0,-1,IF(MASlope>0,1,0));
CloseFactor=If(CLOSE()>M1,1,If(CLOSE()<M1,-1,0));
//
MACDbar1=12*$factor;
MACDbar2=24*$factor;
MACDosc=9*$factor;
//
MACDFactor=MACD(BAR1=MACDbar1, BAR2=MACDbar2, OSC=MACDosc, CALC=Close, STYLE=Exponential, DEFAULT=Oscillator);
MACDPosition=IF(MACDFactor>0,1,IF(MACDFactor<0,-1,0));
//
TEInd=(TMDirection+TMTrendDirection+MomDirection+MADirection+CloseFactor+MaCDPosition);
//
TEIMAadj=MA(TEInd, BARS=3*$factor, STYLE=Exponential, CALC=CLOSE);
//
TEIMAadj

Hi Michael,

I ran into the issue you have struck sometime ago. You cannot use #$ and $ to input a number variable. That functionality is limited Bar variables.

You can get around the issue with a little, as yet undocumented, scripting trickery as explained by Mathew in the thread Scripting: Variables and Properties.

Cheers

Trevor

So I have changed the code to this, but it does absolutely nothing. Am I not getting it?

/This is the 3period exponential MA of the TEI
//
//sample factor code only
//#$BBBMA=8;
//#$BIMAsma=5;
//BIMAplot=MA(BBBIndex,BARS=$BBBMA, STYLE=Exponential, CALC=Close, TOOLNAME=BIMA);
//
//
#$factor=10;
factor1=VARTOLIST(VAL=$factor)
//
//TM1 factors
TMbar1=4*factor1;
TMbar2=10*factor1;
TMosc=29*factor1:
//
TM1=MACD(BAR1=TMbar1, BAR2=TMbar2, OSC=TMbar3, CALC=HLC, STYLE=Exponential);
TM2=OFFSET(TM1, OFFSET=2);
//
TMDirection=IF((TM1-TM2)<0, -1, IF((TM1-TM2)>0,1,0));
//
TMTrendDirection=IF(TM1<0,-1,IF(TM1>0,1,0));
//
//MA factors
MAbars=12*factor1;
MAoffset=3*factor1;
//
M1=MA(BARS=MAbars, STYLE=Exponential);
M2=OFFSET(M1, OFFSET=MAoffset); 
//
MomDirection=IF((M1-M2)>0,1,IF((M1-M2)<0,-1,0));
//
M3offest=1*factor1
M3=OFFSET(M1, OFFSET=M3offset);
//
MASlope=M1-M3;
MADirection=IF(MASlope<0,-1,IF(MASlope>0,1,0));
CloseFactor=If(CLOSE()>M1,1,If(CLOSE()<M1,-1,0)); 
//
MACDbar1=12*factor1;
MACDbar2=24*factor1;
MACDosc=9*factor1;
//
MACDFactor=MACD(BAR1=MACDbar1, BAR2=MACDbar2, OSC=MACDosc, CALC=Close, STYLE=Exponential, DEFAULT=Oscillator);
MACDPosition=IF(MACDFactor>0,1,IF(MACDFactor<0,-1,0));
//
TEInd=(TMDirection+TMTrendDirection+MomDirection+MADirection+CloseFactor+MaCDPosition);
//
TEIMAadj=MA(TEInd, BARS=3*factor1, STYLE=Exponential, CALC=CLOSE);
//
TEIMAadj

Hi Michael,

It appears that you cannot undertake calculations with the #$ variables.

I tried the simple MA plot script from the KB article Bar Variables and Properties :

#$MA1= 20 ;
#$MA2= 50 ;
plot1=MA(Bars=$MA1);
plot2=MA(Bars=$MA2);

This code will work as shown in the above KB article, with MA1 and MA2 appearing and active in the Properties Panel list.

However, if you change the code to:

#$MA1= 20 ;
#$MA2= 50 ;
plot1=MA(Bars=$MA1 * 2);
plot2=MA(Bars=$MA2);

You will find that the MA1 has disappeared from the Properties Panel list.

This seems to stymie what you are attempting to achieve.

We’ll have to hope that the Optuma Genii can come up with a solution that makes to use of the #$var function much more flexible.

Cheers

Trevor

Hi Michael (and thanks Trevor)

Unfotunately I can not see us ever getting this to work

plot1=MA(Bars=$MA1 * 2);

There is a lot of work involved in pre-parsing that and while I understand it is inconvenient, you can add more variables for the unique values you need. Given the amount of work needed, and the existance of an alternative, this will never get high enough in the priority list to get addressed.

All the best

Mathew