Forex Factory (https://www.forexfactory.com/)
-   Trading Discussion (https://www.forexfactory.com/forum/11-trading-discussion)
-   -   VT Dumb Syntax Questions (https://www.forexfactory.com/thread/6034-vt-dumb-syntax-questions)

pmurfin Jun 22, 2006 5:06am | Post# 1

VT Dumb Syntax Questions
 
Hi

A few dumb questions from a newbe ... bear with me!

1. how do i construct this in the VT language?

if ( x > y and a < b) then
output_variable = 1;
else if ( x < y and a < b) then
output_variable = -1;
else
output_variable = 0;
endif

2) then if the output_variable is 1 paint a buy arrow on the chart below the bar , if the output_variable is -1 paint a sell arrow in the chart above the bar and if the output_variable is 0 paint nothing.

3) can I refer to custom indicators in code?

4) how in code do i determine the current time period?

5) can i calculate a moving average in custom indicator code for a different time frame than the chart is in ... e.g. in a custome indicator designed for a 30 minute chart can i calculate a daily moving average?


THANKS !!!!!!!


Paul

Bemac Jun 22, 2006 10:10am | Post# 2

Hey Paul,

Judging by the time you posted this, it looks like you are in a different timzone than I am. So I thought I would post this before you log off.

I have to run to a meeting right now and will post code etc later but meanwhile...

Yes to both. although the higher timeframe ma is not exact.

A 14 bar MA on a 30 min Chart would be "Similar" to a 7 Bar MA on a 1 Hour Chart.

Bemac Jun 22, 2006 1:24pm | Post# 3

Hi

A few dumb questions from a newbe ... bear with me!

1. how do i construct this in the VT language?

if ( x > y and a < b) then
output_variable = 1;
else if ( x < y and a < b) then
output_variable = -1;
else
output_variable = 0;
endif

2) then if the output_variable is 1 paint a buy arrow on the chart below the bar , if the output_variable is -1 paint a sell arrow in the chart above the bar and if the output_variable is 0 paint nothing.

3) can I refer to custom indicators in code?

4) how in code do i determine the current time period?

5) can i calculate a moving average in custom indicator code for a different time frame than the chart is in ... e.g. in a custome indicator designed for a 30 minute chart can i calculate a daily moving average?


THANKS !!!!!!!


Paul
Firstly, you would have to do it in a Strategy, not an indicator.

1)
MyVariable:=IF( x > y and a < b, 1, If( x < y and a < b ,-1, 0));

The value of "MyVariable" will be either 1, -1 or 0.

2)
BuySetup:=MyVariable= 1;
SellSetup:=MyVariable= -1;
OR, depending on the result you want, you may need to write it this way.
BuySetup:=Cross(MyVariable,0.5);
SellSetup:=Cross(-0.5,MyVariable);
The latter will result being True Only When it happens and not While it Continues to be True.

Define BuySetup & SellSetup as Outputs and Checkmark beside Graphic.
Select the Graphic Tab and add the arrow above/below, colour & size.

3)Yes. But ony one Output of that indicator. I find it simpler in most cases just to add the indicator code itself in entirity.

4) I actually posted a snippet for exactly that a couple of days ago.
"See Auto Timeframe Snippet" thread here.

5) Yes and you can make it as simple or complicated as you like.
Simple: Do the math. MA Period*(Desired Timeframe/Actual Timeframe)
ie. 4 hour{240 min} 21 bar MA plotted on a 30 Minute Chart.
21*(240/30)= 168. {I know I don't need the brackets, it's just a visual aid for me}
This will Not be Exact becase the average of 168 closes on a 30 minute Chart may not be the same as the average of 21 closes on a 240 minute Chart. But it will be very close.

Complicated: requires a bit of code to do basically the same thing but can have Input options to make it more user friendly like Chosing a timeframe to pull the MA from and how many Periods you want it based on.

I have one lying around here somewhere. I'll post it in the New section.

pmurfin Jun 22, 2006 3:44pm | Post# 4

Bemac

Thanks so much ... This website is amazing because of the help offered by those who know to those who do not ... it is great to be welcomed into the community ...

Very very much appreciated

Paul

Bemac Jun 22, 2006 4:58pm | Post# 5

Bemac

Thanks so much ... This website is amazing because of the help offered by those who know to those who do not ... it is great to be welcomed into the community ...

Very very much appreciated

Paul
Your welcome Paul. Hope it helps.
I posted that Variable MA btw in Indicators & Trading Systems Only


© Forex Factory