how to suspend trading for a period of time in Power Lang?
Posted: 13 Feb 2011
Hello,talented programers,
I tried to write code which suspend trading for a period of days (ex. 10days) after the sum of past 3 position loss is reaching -400. It acts like circuit break when there is a series loss, suspend for a while before entering new trades:
But I have 2 questions:
1.how do i tell the program to suspend for 10 days and then begin to trade again?
2.after suspension for 10 days, how do i tell the program to recalculate var1 again without counting the positionprofit before suspension? Current definiton of var1=positioninputsprofit(1)+positionprofit(2)+positionprofit(3);, it will always take the positionprofit before suspension in again , how to i have a cut off on this?
Any good idea on this?
sample code is provided below:
inputs: Price( Close ), Length( 200);
variables: var0( 0 ) ,var1(0);
var0=AverageFC( Price, Length ) ;
var1=positioninputsprofit(1)+positionprofit(2)+positionprofit(3);
condition2 = Price crosses above var0 and marketposition=0;
if condition2 then
Buy ( "MACrossLE" ) next bar at market ;
condition3 = price crosses below var0 and marketposition=1;
if condition3 then
Sell ( "MACrossLX" ) next bar at market ;
Condition1 = var1 < -100 and marketposition=1;
if condition1 then
Sell ("suspend trading") next bar at market
I tried to write code which suspend trading for a period of days (ex. 10days) after the sum of past 3 position loss is reaching -400. It acts like circuit break when there is a series loss, suspend for a while before entering new trades:
But I have 2 questions:
1.how do i tell the program to suspend for 10 days and then begin to trade again?
2.after suspension for 10 days, how do i tell the program to recalculate var1 again without counting the positionprofit before suspension? Current definiton of var1=positioninputsprofit(1)+positionprofit(2)+positionprofit(3);, it will always take the positionprofit before suspension in again , how to i have a cut off on this?
Any good idea on this?
sample code is provided below:
inputs: Price( Close ), Length( 200);
variables: var0( 0 ) ,var1(0);
var0=AverageFC( Price, Length ) ;
var1=positioninputsprofit(1)+positionprofit(2)+positionprofit(3);
condition2 = Price crosses above var0 and marketposition=0;
if condition2 then
Buy ( "MACrossLE" ) next bar at market ;
condition3 = price crosses below var0 and marketposition=1;
if condition3 then
Sell ( "MACrossLX" ) next bar at market ;
Condition1 = var1 < -100 and marketposition=1;
if condition1 then
Sell ("suspend trading") next bar at market