Re: [amibroker] How to make a multi trading strategies in one backtest?

 

Maybe you post wrong program. I run your program. I get error "R1TradeCount used without initializing".

>>  I got some problems in the cut loss and stop profit price.

What is the problems? Too high? Too low?

If you comment out 2 AplyStop line is your results now good?


On 12/05/2016 2:49 AM, wonglongchun@gmail.com [amibroker] wrote:
 

Hi all!
I am writing a back-testing file and the strategy has 2 signals :R1 and R2, they have different buy and sell signals.

And I used for loop function to make the flow of this strategy and I got some problems in the cut loss and stop profit price. I want to these 2 signals have 2 different stop price. How can I make it? Thanks!




Buy1 = C > O; //It's just a example

Sell1 = C > Ref(C, -1); //It's just a example

Short1 = O > C; //It's just a example

Cover1 = C < Ref(C, -1); //It's just a example


R1ProfitPoint = 150;

R1LossPoint = 70;


Buy2 = H > Ref(H, -1); //It's just a example

Sell2 = C > Ref(C, -1); //It's just a example

Short2 = L > Ref(L, -1); //It's just a example

Cover2 = C < Ref(C, -1); //It's just a example



R2ProfitPoint = 200;

R2LossPoint = 90;


BuyCondition = 0;

SellCondition = 0;

ShortCondition = 0;

CoverCondition = 0;


PositionHold = 0;

ProfitPoint = 0;

LossPoint = 0;

R1 = 0;

R2 = 0;


for (i = 0; i < BarCount; i++)

{

if (Buy1[i] AND PositionHold == 0)

{

BuyCondition[i] = 1;

PositionHold ++;

ProfitPoint = R1ProfitPoint;

LossPoint = R1LossPoint;

R1 = 1;

}

else if (Short1[i] AND PositionHold == 0)

{

ShortCondition[i] = 1;

PositionHold --;

R1TradeCount ++;

ProfitPoint = R1ProfitPoint;

LossPoint = R1LossPoint;

R1 = 1;

}

else if (Sell1[i] && PositionHold > 0 AND R1 == 1)

{

SellCondition[i] = 1;

PositionHold = 0;

R1 = 0;

}

else if (Cover1[i] && PositionHold < 0 AND R1 == 1)

{

CoverCondition[i] = 1;

PositionHold = 0;

R1 = 0;

}

else if (Buy2[i] AND PositionHold == 0)

{

BuyCondition[i] = 1;

PositionHold ++;

ProfitPoint = R2ProfitPoint;

LossPoint = R2LossPoint;

R2 = 1;

}

else if (Short2[i] AND PositionHold == 0)

{

ShortCondition[i] = 1;

PositionHold --;

ProfitPoint = R2ProfitPoint;

LossPoint = R2LossPoint;

R2 = 1;

}

else if (Sell2[i] && PositionHold > 0 AND R2 == 1)

{

SellCondition[i] = 1;

PositionHold = 0;

R2 = 0;

}

else if (Cover2[i] && PositionHold < 0 AND R2 == 1)

{

CoverCondition[i] = 1;

PositionHold = 0;

R2 = 0;

}

}


Buy = BuyCondition;

Sell = SellCondition;

Short = ShortCondition;

Cover = CoverCondition;


ApplyStop(stopTypeProfit, stopModePoint, ProfitPoint);

ApplyStop(stopTypeLoss, stopModePoint, LossPoint);



__._,_.___

Posted by: Sab Nys <SabNys@yahoo.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (5)

Upgrade your account with the latest Yahoo Mail app
Get organized with the fast and easy-to-use Yahoo Mail app. Upgrade today!

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/


.

__,_._,___


EmoticonEmoticon