Dear MC,
I want to program the take profit and cut loss command , but the "contractprofit" can not deal with trade( I optimization the signal to the trading, there isn't any trade result). Could you check my mistake?
Thanks.
begin
if A > B then
buy ( "RSI-Long" ) 100 contracts next bar at market;
end;
condition20 = contractprofit > 800;
condition21 = contractprofit < -1 * 400;
IF CONDITION20 or CONDITION21 THEN
BEGIN
IF CONDITION20 THEN
sell from entry( "RSI-LONG" ) 100 contracts next bar at market;
IF CONDITION21 THEN
SELL FROM ENTRY( "RSI-LONG" ) 100 CONTRACTS NEXT BAR AT MARKET;
end;
contractprofit can't trading? [SOLVED]
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
-
- Posts: 25
- Joined: 05 Jan 2019
- Has thanked: 6 times
Re: contractprofit can't trading?
SORRY,it's my first time post code.See post #1 & #2
viewtopic.php?t=11713
I don't know how to program "contractprofit" for take profit and cut loss.
Thank you.
Code: Select all
inputs:iEMAup1len( 14 ), iEMAdown1len( 14 ), iAVGRSI1len( 5 ), iEXTAVGRSI1len( 10 ), ioversell( 30 ), oEMAup1len( 14 ), oEMAdown1len( 14 ), oAVGRSI1len( 5 ),
oEXTAVGRSI1len( 10 ), ooverbuy( 70 ), BUYQTY( 100 ), takeprofit( 800 ), cutlossamt(400);
variables:iUp1( 0 ), iDown1( 0 ), iEMAup1( 0 ), iEMAdown1( 0 ), iRS1( 0 ), iRSI1( 0 ), iAVGRSI1( 0 ), iEXTAVGRSI1( 0 ), oUp1( 0 ), oDown1( 0 ), oEMAup1( 0 ),
oEMAdown1( 0 ), oRS1( 0 ), oRSI1( 0 ), oAVGRSI1( 0 ), oEXTAVGRSI1( 0 );
iup1 = iff( (close[1] - open[1] ) > 0, close - close[1], 0 );
idown1 = iff( ( close[1] - open[1] ) < 0, close[1] - close, 0 );
iEMAup1 = SmoothedAverage( iup1, iEMAup1len );
iEMAdown1 = smoothedaverage( idown1, iEMAdown1len );
if iEMAdown1 <> 0 then
iRS1 = iEMAup1 / iEMAdown1;
if 1 + iRS1 <> 0 then
iRSI1 = 100 - 100 / ( 1 + iRS1 );
iAVGRSI1 = AVERAGEFC( iRSI1, iAVGRSI1len );
iEXTAVGRSI1 = AVERAGEFC( iRSI1, iextAVGRSI1len );
oup1 = iff( (close[1] - open[1] ) > 0, close - close[1], 0 );
odown1 = iff( ( close[1] - open[1] ) < 0, close[1] - close, 0 );
oEMAup1 = SmoothedAverage( oup1, oEMAup1len );
oEMAdown1 = smoothedaverage( odown1, oEMAdown1len );
if oEMAdown1 <> 0 then
oRS1 = oEMAup1 / oEMAdown1;
if 1 + oRS1 <> 0 then
oRSI1 = 100 - 100 / ( 1 + oRS1 );
oAVGRSI1 = AVERAGEFC( oRSI1, oAVGRSI1len );
oEXTAVGRSI1 = AVERAGEFC( oRSI1, oextAVGRSI1len );
begin
if iAVGRSI1 > iEXTAVGRSI1 and iAVGRSI1 crosses above ioversell then
buy ( "RSI-Long" ) BUYQTY contracts next bar at market;
end;
condition20 = contractprofit > takeprofit;
condition21 = contractprofit < -1 * cutlossamt;
IF CONDITION20 or CONDITION21 THEN
BEGIN
IF CONDITION20 THEN
sell from entry( "RSI-LONG" ) BUYQTY contracts next bar at market;
IF CONDITION21 THEN
SELL FROM ENTRY( "RSI-LONG" ) BUYQTY CONTRACTS NEXT BAR AT MARKET;
end;
- FinanceStrategy
- Posts: 7
- Joined: 05 Jun 2019
- Has thanked: 1 time
- Been thanked: 3 times
- Contact:
Re: contractprofit can't trading?
I corrected your code and works...SORRY,it's my first time post code.See post #1 & #2
viewtopic.php?t=11713
I don't know how to program "contractprofit" for take profit and cut loss.
Thank you.
[/code]
Firstly, I changed the last part of your code, there was an error.
Maybe you have to reduce the dollar take-profit and stop-loss in inputs.
Contractprofit calculates the position profit per contract or share. If you buy 100 shares and your take-profit is 800$, then every stock has to gain 800$ --> 800$ x 100 --> your real take-profit is 80.000$.
For example, in my backtest, I try MSFT with 5$ TP and 5$ SL.
Code: Select all
inputs:iEMAup1len( 14 ), iEMAdown1len( 14 ), iAVGRSI1len( 5 ), iEXTAVGRSI1len( 10 ), ioversell( 30 ), oEMAup1len( 14 ), oEMAdown1len( 14 ), oAVGRSI1len( 5 ),
oEXTAVGRSI1len( 10 ), ooverbuy( 70 ), BUYQTY( 100 ), takeprofit( 5 ), cutlossamt(5);
variables:iUp1( 0 ), iDown1( 0 ), iEMAup1( 0 ), iEMAdown1( 0 ), iRS1( 0 ), iRSI1( 0 ), iAVGRSI1( 0 ), iEXTAVGRSI1( 0 ), oUp1( 0 ), oDown1( 0 ), oEMAup1( 0 ),
oEMAdown1( 0 ), oRS1( 0 ), oRSI1( 0 ), oAVGRSI1( 0 ), oEXTAVGRSI1( 0 );
iup1 = iff( (close[1] - open[1] ) > 0, close - close[1], 0 );
idown1 = iff( ( close[1] - open[1] ) < 0, close[1] - close, 0 );
iEMAup1 = SmoothedAverage( iup1, iEMAup1len );
iEMAdown1 = smoothedaverage( idown1, iEMAdown1len );
if iEMAdown1 <> 0 then
iRS1 = iEMAup1 / iEMAdown1;
if 1 + iRS1 <> 0 then
iRSI1 = 100 - 100 / ( 1 + iRS1 );
iAVGRSI1 = AVERAGEFC( iRSI1, iAVGRSI1len );
iEXTAVGRSI1 = AVERAGEFC( iRSI1, iextAVGRSI1len );
oup1 = iff( (close[1] - open[1] ) > 0, close - close[1], 0 );
odown1 = iff( ( close[1] - open[1] ) < 0, close[1] - close, 0 );
oEMAup1 = SmoothedAverage( oup1, oEMAup1len );
oEMAdown1 = smoothedaverage( odown1, oEMAdown1len );
if oEMAdown1 <> 0 then
oRS1 = oEMAup1 / oEMAdown1;
if 1 + oRS1 <> 0 then
oRSI1 = 100 - 100 / ( 1 + oRS1 );
oAVGRSI1 = AVERAGEFC( oRSI1, oAVGRSI1len );
oEXTAVGRSI1 = AVERAGEFC( oRSI1, oextAVGRSI1len );
begin
if iAVGRSI1 > iEXTAVGRSI1 and iAVGRSI1 crosses above ioversell then
buy ( "RSI-Long" ) BUYQTY contracts next bar at market;
end;
condition20 = contractprofit > takeprofit;
condition21 = contractprofit < -1 * cutlossamt;
IF CONDITION20 or CONDITION21 THEN
sell ( "RSI-EXIT" ) BUYQTY contracts next bar at market;
-
- Posts: 25
- Joined: 05 Jan 2019
- Has thanked: 6 times
Re: contractprofit can't trading? [SOLVED]
I corrected your code and works...SORRY,it's my first time post code.See post #1 & #2
viewtopic.php?t=11713
I don't know how to program "contractprofit" for take profit and cut loss.
Thank you.
[/code]
Firstly, I changed the last part of your code, there was an error.
Maybe you have to reduce the dollar take-profit and stop-loss in inputs.
Contractprofit calculates the position profit per contract or share. If you buy 100 shares and your take-profit is 800$, then every stock has to gain 800$ --> 800$ x 100 --> your real take-profit is 80.000$.
For example, in my backtest, I try MSFT with 5$ TP and 5$ SL.
Code: Select all
inputs:iEMAup1len( 14 ), iEMAdown1len( 14 ), iAVGRSI1len( 5 ), iEXTAVGRSI1len( 10 ), ioversell( 30 ), oEMAup1len( 14 ), oEMAdown1len( 14 ), oAVGRSI1len( 5 ), oEXTAVGRSI1len( 10 ), ooverbuy( 70 ), BUYQTY( 100 ), takeprofit( 5 ), cutlossamt(5); variables:iUp1( 0 ), iDown1( 0 ), iEMAup1( 0 ), iEMAdown1( 0 ), iRS1( 0 ), iRSI1( 0 ), iAVGRSI1( 0 ), iEXTAVGRSI1( 0 ), oUp1( 0 ), oDown1( 0 ), oEMAup1( 0 ), oEMAdown1( 0 ), oRS1( 0 ), oRSI1( 0 ), oAVGRSI1( 0 ), oEXTAVGRSI1( 0 ); iup1 = iff( (close[1] - open[1] ) > 0, close - close[1], 0 ); idown1 = iff( ( close[1] - open[1] ) < 0, close[1] - close, 0 ); iEMAup1 = SmoothedAverage( iup1, iEMAup1len ); iEMAdown1 = smoothedaverage( idown1, iEMAdown1len ); if iEMAdown1 <> 0 then iRS1 = iEMAup1 / iEMAdown1; if 1 + iRS1 <> 0 then iRSI1 = 100 - 100 / ( 1 + iRS1 ); iAVGRSI1 = AVERAGEFC( iRSI1, iAVGRSI1len ); iEXTAVGRSI1 = AVERAGEFC( iRSI1, iextAVGRSI1len ); oup1 = iff( (close[1] - open[1] ) > 0, close - close[1], 0 ); odown1 = iff( ( close[1] - open[1] ) < 0, close[1] - close, 0 ); oEMAup1 = SmoothedAverage( oup1, oEMAup1len ); oEMAdown1 = smoothedaverage( odown1, oEMAdown1len ); if oEMAdown1 <> 0 then oRS1 = oEMAup1 / oEMAdown1; if 1 + oRS1 <> 0 then oRSI1 = 100 - 100 / ( 1 + oRS1 ); oAVGRSI1 = AVERAGEFC( oRSI1, oAVGRSI1len ); oEXTAVGRSI1 = AVERAGEFC( oRSI1, oextAVGRSI1len ); begin if iAVGRSI1 > iEXTAVGRSI1 and iAVGRSI1 crosses above ioversell then buy ( "RSI-Long" ) BUYQTY contracts next bar at market; end; condition20 = contractprofit > takeprofit; condition21 = contractprofit < -1 * cutlossamt; IF CONDITION20 or CONDITION21 THEN sell ( "RSI-EXIT" ) BUYQTY contracts next bar at market;
OK, I GOT IT. THANK YOU SO MUCH.