how to suspend trading for a period of time in Power Lang?

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
justmake
Posts: 42
Joined: 21 Dec 2010
Has thanked: 15 times
Been thanked: 1 time

how to suspend trading for a period of time in Power Lang?

Postby justmake » 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

User avatar
TJ
Posts: 7743
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: how to suspend trading for a period of time in Power Lan

Postby TJ » 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?
.......
1. you have to set up some counters.

here's the idea in pseudo code:
note: you just have to think out loud... and write the logic down as you "think".

Code: Select all

input:
standaside.dollar(-400),
standaside.days(10);

var:
standaside(false),
standaside.count(0);

if loss < standaside.dollar then
begin
standaside = true;
standaside.count = 1;
end;

if standaside = true
and standaside.count < standaside.days +1
then
begin
if date <> date[1] then standaside.count = standaside.count + 1;
end
else
begin
standaside = false;
standaside.count = 0;
end;

... ...

if standaside = false then
begin
{your trading code here}
end;

ps. pls use code tag to wrap your codes. It makes reading easier.
viewtopic.php?f=16&t=11713

justmake
Posts: 42
Joined: 21 Dec 2010
Has thanked: 15 times
Been thanked: 1 time

Re: how to suspend trading for a period of time in Power Lan

Postby justmake » 14 Feb 2011

Hello,TJ,

Thanks for the detailed suggestion:) I know what you mean buy write down the logic when I think. I have been scratching my head for the past 2 nights and sometimes I just cannot get it through.
That's when experience counts I guess.

thanks a lot!
Justmake
p.s.any tips for my question 2?

User avatar
TJ
Posts: 7743
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: how to suspend trading for a period of time in Power Lan

Postby TJ » 14 Feb 2011

Hello,TJ,

Thanks for the detailed suggestion:) I know what you mean buy write down the logic when I think. I have been scratching my head for the past 2 nights and sometimes I just cannot get it through.
That's when experience counts I guess.

thanks a lot!
Justmake
p.s.any tips for my question 2?
Developing an autotrading system is a major undertaking.
Words do not easily describe such a complex operation.
I would suggest you to begin with a flow chart;
try to visualize the logistics of the system you have in mind.
Then do one section of code at a time, and to test the functionality of each logic section by section.

justmake
Posts: 42
Joined: 21 Dec 2010
Has thanked: 15 times
Been thanked: 1 time

Re: how to suspend trading for a period of time in Power Lan

Postby justmake » 14 Feb 2011

Hello,TJ,

Thanks for the suggestion. I will do that and see if I can solve the problem.

thanks again for the advice:)
JM


Return to “User Contributed Studies and Indicator Library”