Hello All,
I have placed the query for placing order from AFL amibroker. with the below conditions.
1) first order should be 1;
2) If any order exited by Stop loss or target (sell or cover) the quantity should be 1;
3) if the stoploss or target not hit then the queantity should be 2; way means on next buy or short it will close exsting 1 quantity and place one more quantity and continue next trade;
Kindly help me on this how to trade with above logic. I have given which modifified but i am declaring the values as static in starting hence the it will not change;
Hoping any one will help me and fix the issue.
I have placed the query for placing order from AFL amibroker. with the below conditions.
1) first order should be 1;
2) If any order exited by Stop loss or target (sell or cover) the quantity should be 1;
3) if the stoploss or target not hit then the queantity should be 2; way means on next buy or short it will close exsting 1 quantity and place one more quantity and continue next trade;
Kindly help me on this how to trade with above logic. I have given which modifified but i am declaring the values as static in starting hence the it will not change;
Hoping any one will help me and fix the issue.
Code:
AT_QUANTITY=1;
Next_QUANTITY=0;
if(shouldSquareOff() == 1) {
squareOffPosition();
}
else {
if ( LastValue(Buy) == True AND isFirstOrder() == 0 )
{
placeOrderAdvancedNew(AT_EXCHANGE, AT_INSTRUMENT, Name(), "BUY", AT_PRODUCT_TYPE, AT_ORDER_TYPE, AT_QUANTITY, 0, defaultTriggerPrice(), defaultDisclosedQuantity(), AT_OPTION_TYPE, AT_STRIKE_PRICE, AT_EXPIRY, defaultClientId(), defaultValidity(), defaultTraderType(), defaultMarketProtectionPct(), defaultStrategyId(), defaultComments(),
"regular", 0, 0, 0);
Next_QUANTITY=AT_QUANTITY+1;
}
if ( LastValue(Short) == True AND isFirstOrder() == 0)
{
placeOrderAdvancedNew(AT_EXCHANGE, AT_INSTRUMENT, Name(), "SELL", AT_PRODUCT_TYPE, AT_ORDER_TYPE, AT_QUANTITY,0, defaultTriggerPrice(), defaultDisclosedQuantity(), AT_OPTION_TYPE, AT_STRIKE_PRICE, AT_EXPIRY, defaultClientId(), defaultValidity(), defaultTraderType(), defaultMarketProtectionPct(), defaultStrategyId(), defaultComments(),
"regular", 0, 0, 0);
Next_QUANTITY=AT_QUANTITY+1;
}
if ( LastValue(Buy) == True )
{
placeOrderAdvancedNew(AT_EXCHANGE, AT_INSTRUMENT, Name(), "BUY", AT_PRODUCT_TYPE, AT_ORDER_TYPE, QTY, 0, defaultTriggerPrice(), defaultDisclosedQuantity(), AT_OPTION_TYPE, AT_STRIKE_PRICE, AT_EXPIRY, defaultClientId(), defaultValidity(), defaultTraderType(), defaultMarketProtectionPct(), defaultStrategyId(), defaultComments(),
"regular", 0, 0, 0);
Next_QUANTITY=AT_QUANTITY+1;
}
if ( LastValue(Short) == True )
{
placeOrderAdvancedNew(AT_EXCHANGE, AT_INSTRUMENT, Name(), "SELL", AT_PRODUCT_TYPE, AT_ORDER_TYPE, QTY,0, defaultTriggerPrice(), defaultDisclosedQuantity(), AT_OPTION_TYPE, AT_STRIKE_PRICE, AT_EXPIRY, defaultClientId(), defaultValidity(), defaultTraderType(), defaultMarketProtectionPct(), defaultStrategyId(), defaultComments(),
"regular", 0, 0, 0);
Next_QUANTITY=AT_QUANTITY+1;
}
}
StopLevel = Param( "Stop Loss (%)", 0.25, 0.01, 10, 0.01 );
TgtLevel = Param( "Profit target (%)", 0.5, 0.01, 10, 0.01 );
ApplyStop( stopTypeLoss, stopModePercent, StopLevel, True );
ApplyStop( stopTypeProfit, stopModePercent, TgtLevel, True );
Equity( 1, 0 );
sellcond2=Sell==2; covercond2=Cover==2;
sellcond3=Sell==3; covercond3=Cover==3;
Sell=ExRem(Sell,Cover);
Cover=ExRem(Cover,Sell);
if ( LastValue(covercond2) ==True OR LastValue(covercond3) ==True)
{
tradeType="Buy";
placeOrderAdvancedNew(AT_EXCHANGE, AT_INSTRUMENT, Name(), "BUY", AT_PRODUCT_TYPE, AT_ORDER_TYPE, 1, 0, defaultTriggerPrice(), defaultDisclosedQuantity(), AT_OPTION_TYPE, AT_STRIKE_PRICE, AT_EXPIRY, defaultClientId(), defaultValidity(), defaultTraderType(), defaultMarketProtectionPct(), defaultStrategyId(), defaultComments(),
"regular", 0, 0, 0);
//AT_QUANTITY = Param("Order quantity (lot size)", 1, 0, 300000, 10);
Next_QUANTITY=AT_QUANTITY;
}
if ( LastValue(sellcond2)==True OR LastValue(sellcond3) ==True)
{
placeOrderAdvancedNew(AT_EXCHANGE, AT_INSTRUMENT, Name(), "SELL", AT_PRODUCT_TYPE, AT_ORDER_TYPE, 1,0, defaultTriggerPrice(), defaultDisclosedQuantity(), AT_OPTION_TYPE, AT_STRIKE_PRICE, AT_EXPIRY, defaultClientId(), defaultValidity(), defaultTraderType(), defaultMarketProtectionPct(), defaultStrategyId(), defaultComments(),
"regular", 0, 0, 0);
Next_QUANTITY=AT_QUANTITY;
//AT_QUANTITY = Param("Order quantity (lot size)", 1, 0, 300000, 10);
}
QTY=Next_QUANTITY;