Help - Search - Members - Calendar
Full Version: Need Help Coding Conditioning Part Of Ts
Visual Trading Systems User Forums > VTTRADER TRADING SYSTEMS > TRADING SYSTEMS PROGRAMMING QUESTIONS
Cancun
Hello Chris;

I have been trying to figure out how to adapt the code logic of one of the Trading Systems that you coded for me not a long time ago (see: http://forum.vtsystems.com/index.php?showtopic=11893) to another one that I have.

The problem is that I am having a hard time to figure out how to define the long entry and short entry conditions:

This is what you did:
---------------------------------------------------------------------------------------------------------------
Td:= If(H>ValueWhen(1,Pv>0,Pv), 1, If(L<ValueWhen(1,Tv>0,Tv), -1, 0));

{UpTrend=1 | DownTrend =-1}

Tdv:= ValueWhen(1,Td<>0,Td);

{Define Final Trade Entry/Exit Criteria}

LongEntryCond1:= Cross(Tdv,0);
LongEntryCond2:= Sd>0;
LongEntryCond3:= C>Hilo;

ShortEntryCond1:= Cross(0,Tdv);
ShortEntryCond2:= Sd<0;
ShortEntryCond3:= C<Hilo;

LongEntryCondsMet:= LongEntryCond1=1 AND LongEntryCond2=1 AND LongEntryCond3=1;
LongEntryBarHigh:= valuewhen(1,LongEntryCondsMet,H);
LongEntryBarRange:= valuewhen(1,LongEntryCondsMet,H-L);
LongEntryLevel:= LongEntryBarHigh + (LongEntryBarRange*(RP/100)) + (If(CT=0,_Spread,0));

ShortEntryCondsMet:= ShortEntryCond1=1 AND ShortEntryCond2=1 AND ShortEntryCond3=1;
ShortEntryBarLow:= valuewhen(1,ShortEntryCondsMet,L);
ShortEntryBarRange:= valuewhen(1,ShortEntryCondsMet,H-L);
ShortEntryLevel:= ShortEntryBarLow - (ShortEntryBarRange*(RP/100)) - (If(CT=1,_Spread,0));

{test}

LongEntryLevelResetCond:= SignalFlag(LongEntryCondsMet=1,ShortEntryCondsMet=1);
ShortEntryLevelResetCond:= SignalFlag(ShortEntryCondsMet=1,LongEntryCondsMet=1);

DisplayLongEntryLevel:= if(LongEntryLevelResetCond=1,LongEntryLevel,NULL);
DisplayShortEntryLevel:= if(ShortEntryLevelResetCond=1,ShortEntryLevel,NULL);

{test}

LongEntrySetup:= Cross(C,DisplayLongEntryLevel);
LongExitSetup:= Cross(DisplayShortEntryLevel,C);

ShortEntrySetup:= Cross(DisplayShortEntryLevel,C);
ShortExitSetup:= Cross(C,DisplayLongEntryLevel);
---------------------------------------------------------------------------------------------------------------

And this is the main logic of the TS that I am trying to modify so that the Long Entries and Short Entries are shifted the same way.

---------------------------------------------------------------------------------------------------------------
UpTrend:= (MA1>MA2) and not ERR;
DownTrend:= (MA2>MA1) and not ERR;

{Create Entry and Exit Signals}

LongEntrySignal:= (TradeCondition=0 and UpTrend) or (TradeCondition=-1 and ShortExitSignal=1 and UpTrend);
LongExitSignal:= TradeCondition=1 and DownTrend;
ShortEntrySignal:= (TradeCondition=0 and DownTrend) or (TradeCondition=1 and LongExitSignal=1 and DownTrend);
ShortExitSignal:= TradeCondition=-1 and UpTrend;

{Determine Trade Direction and Condition}

TradeCondition:= if((ShortExitSignal and LongEntrySignal) or LongEntrySignal, 1,
if((LongExitSignal and ShortEntrySignal) or ShortEntrySignal, -1,
if(LongExitSignal or ShortExitSignal, 0,
PREV(0))));

---------------------------------------------------------------------------------------------------------------

I did this but I am just getting a bunch of small dots:

---------------------------------------------------------------------------------------------------------------
UpTrend:= (MA1>MA2) and not ERR;
DownTrend:= (MA2>MA1) and not ERR;

{Define Final Trade Entry/Exit Criteria}

LEnS:= (LongEntryCond1=0 and UpTrend) or (LongEntryCond1=-1 and UpTrend);
SEnS:= (ShortEntryCond1=0 and DownTrend) or (ShortEntryCond1=1 and DownTrend);

LongEntryCond1:= if(LEnS, 1,
if(SEnS, -1,
PREV(0)));

ShortEntryCond1:= if(LEnS, 1,
if(SEnS, -1,
PREV(0)));

LongEntryCondsMet:= LongEntryCond1=1;
LongEntryBarHigh:= valuewhen(1,LongEntryCondsMet,H);
LongEntryBarRange:= valuewhen(1,LongEntryCondsMet,H-L);
LongEntryLevel:= LongEntryBarHigh + (LongEntryBarRange*(RP/100)) + (If(CT=0,_Spread,0));

ShortEntryCondsMet:= ShortEntryCond1=1;
ShortEntryBarLow:= valuewhen(1,ShortEntryCondsMet,L);
ShortEntryBarRange:= valuewhen(1,ShortEntryCondsMet,H-L);
ShortEntryLevel:= ShortEntryBarLow - (ShortEntryBarRange*(RP/100)) - (If(CT=1,_Spread,0));

{test}

LongEntryLevelResetCond:= SignalFlag(LongEntryCondsMet=1,ShortEntryCondsMet=1);
ShortEntryLevelResetCond:= SignalFlag(ShortEntryCondsMet=1,LongEntryCondsMet=1);

DisplayLongEntryLevel:= if(LongEntryLevelResetCond=1,LongEntryLevel,NULL);
DisplayShortEntryLevel:= if(ShortEntryLevelResetCond=1,ShortEntryLevel,NULL);

{test}

LongEntrySetup:= Cross(C,DisplayLongEntryLevel);
LongExitSetup:= Cross(DisplayShortEntryLevel,C);

ShortEntrySetup:= Cross(DisplayShortEntryLevel,C);
ShortExitSetup:= Cross(C,DisplayLongEntryLevel);
---------------------------------------------------------------------------------------------------------------

Could you help me with this problem please?

Regards,
Carlos
cskidmore
Hi Carlos,

Do you still require assistance with this topic?

Regards,
Chris
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.