Home › Forums › Trading System Mentor Course Community › AmiBroker Coding and AFL › A little help please
- This topic is empty.
-
AuthorPosts
-
May 7, 2016 at 5:32 pm #101491JulianCohenParticipant
I am trying to code the following:
The bar has made a lower low
I have tried LLV(L,1) but it doesn’t do what I want. Neither does Outside()
What should I use please?
May 7, 2016 at 5:41 pm #103699JulianCohenParticipantIgnore me…I’m an idiot!!! Which means of course I found it in the last place I chose to look, which should have been the first place I chose to look
May 7, 2016 at 11:05 pm #103700Nick RadgeKeymasterQuote:I found it in the last place I chose to lookIt will ALWAYS be in the last place – you wouldn’t keep on looking for something you’ve already found :woohoo:
May 8, 2016 at 4:20 am #103704JulianCohenParticipantYou have a very relevant point!
June 28, 2017 at 9:01 am #103707TrentRothallParticipantCan someone help with this..
The following statement returns a ARRAY not a number because a array is used in the IIF function.
Maxpos = IIf(IndexUp,10,20);
Is there a easy way to get the result that i’m after? Am i missing something? I need a similar statement to return a number not a array to use in the SetOption(“MaxOpenPositions”,MaxPos);
Cheers
June 29, 2017 at 3:30 am #107164JulianCohenParticipantI thought the above would work:
SYNTAX IIf( EXPRESSION, TRUE_PART, FALSE_PART )
RETURNS ARRAY or NUMBERFrom the Amibroker Help page
June 29, 2017 at 4:24 am #107165LeeDanelloParticipantWhy not try “if” which works bar by bar
June 29, 2017 at 6:19 am #107169TrentRothallParticipantCode:for( i = 0; i < BarCount; i++ ) { if( IndexUp[ i ] ) { SetOption("MaxOpenPositions",10);// this part is executed when condition is met } else { SetOption("MaxOpenPositions",20);// this part is executed when condition is not met } }I tried that but it crashed Ami…
June 29, 2017 at 8:03 am #107166SaidBitarMemberTrent Rothall wrote:Can someone help with this..The following statement returns a ARRAY not a number because a array is used in the IIF function.
Maxpos = IIf(IndexUp,10,20);
Is there a easy way to get the result that i’m after? Am i missing something? I need a similar statement to return a number not a array to use in the SetOption(“MaxOpenPositions”,MaxPos);
Cheers
I tried this before it will not work, here is the workaround from what i remember
you set the position number as max 20 in your case and you control the number of positions from the position size
so it should be one thing like this
MaxPos = 20
positionsize=10%
margin = iif(indexup,100,50);anyhow i will give you the exact workaround later
November 19, 2017 at 3:06 am #103701ZachSwannMemberRounding Issue
This is the code I am using and I have also tried rounding the round
but a few of the stock I end up with 49.379999 for example
BuyLimVal = round(BuyLimitP/0.01);
BuyLim = BuyLimVal * 0.01;Workaround???
November 19, 2017 at 4:05 am #108004LeeDanelloParticipantTry this function
Prec
– adjust number of decimal points of floating point numberMath functions
SYNTAX Prec(ARRAY, precision )
RETURNS ARRAY
FUNCTION Truncates ARRAY to precision decimal places.
EXAMPLE The formula “prec( 10.12981, 2 )” returns 10.120. The formula “prec( 10.12981, 4 )” returns 10.12980.November 19, 2017 at 4:11 am #108005ZachSwannMemberWorks perfectly Cheers
May 14, 2018 at 6:35 pm #103702AnonymousInactiveMultiple exits – “x” (I have used RSI for the example below) OR “exitbars”
I had this code saved before and can’t find it so I am trying to code it again and hitting blanks….I am rusty on the coding and obviously not fully understanding the looping. I will have to revisit that section.
ExitBars = Param(“# Exit Bars”,10,2,100,1);
RSIEx = RSI(14) > 70;
SellSetUp = RSIEx OR ExitBars;
LEx = Ref(SellSetUp,-1);Short = Cover = False;
//=================================================================================
//Looping
//=================================================================================
Buy = 0;
Sell = 0;
PriceAtBuy = 0;
LBIT = 0;
FlagExit = 0;
//=================================================================================for (j = 1; j < BarCount; j++)
{
if (PriceAtBuy==0 AND LE[j])
{
Buy[j] = True;
BuyPrice[j] = LEPrice[j];
PriceAtBuy = BuyPrice[j];
LBIT[j] = 1;if (LBIT[j] > 1 AND (LEx[j] OR OnSecondLastBarOfDelistedSecurity[j]))
{
Sell[j] = True;
SellPrice[j] = Open[j];
PriceAtBuy = 0;
}
}
else
if (PriceAtBuy > 0)
{
LBIT[j] = LBIT[j-1] + 1;
if (LBIT[j] > 1 AND (LEx[j] OR OnSecondLastBarOfDelistedSecurity[j]))
{
Sell[j] = True;
SellPrice[j] = Open[j];
PriceAtBuy = 0;
}
if (LBIT[j] == ExitBars)
{
FlagExit[j] = True;
}if (LBIT[j] > 1 AND (LBIT[j] > ExitBars OR OnSecondLastBarOfDelistedSecurity[j]))
{
Sell[j] = True;
SellPrice[j] = Open[j];
PriceAtBuy = 0;
}
}
}May 14, 2018 at 8:58 pm #108724JulianCohenParticipantThis is my looping code for Exitbars
Code:SellSetup = C > Ref(C,-1) OR C < LMA; LEx = Ref(SellSetUp,-1); ExitBars = Param("# Exit Bars",4,1,15,1); Short = Cover = False; //================================================================================= //Looping //================================================================================= Buy = 0; Sell = 0; PriceAtBuy = 0; LBIT = 0; FlagExit = 0; //================================================================================= for (j = 1; j < BarCount; j++) { if (PriceAtBuy==0 AND LE[j]) { Buy[j] = True; PriceAtBuy = LEPrice[j]; BuyPrice[j] = LEPrice[j]; LBIT[j] = 1; } else if (PriceAtBuy > 0)
{
LBIT[j] = LBIT[j-1]+1;if (LBIT[j] == ExitBars)
{
FlagExit[j] = True;
}if (LBIT[j] > ExitBars)
{
Sell[j] = True;
SellPrice[j] = Open[j];
PriceAtBuy = 0;
}if (LBIT[j]>1 AND LEx[j])
{
Sell[j] = True;
SellPrice[j] = Open[j];
PriceAtBuy = 0;
}if (LBIT[j] >= 1 AND NTEx[j])
{
Sell[j] = True;
SellPrice[j] = C[j];
LPriceAtBuy = 0;
}
}
}
//———————————————————————
LESetUp = IIf(LBIT==0 OR Sell==1,BuySetUp,0); //Long Entry SetUp
LExSetUp = IIf(LBIT>0 AND Sell==0,SellSetup,0); //Long Exit SetupAdd this part at the start of your Entry and Exit signals
Code:NTPeriod = 30;
DN = DateNum();
LastDate = Status(“rangetodate”);
NT = LastDate – LastValue(DN) >= NTPeriod AND DN == LastValue(DN);
LastBarExit = BarIndex() == LastValue(BarIndex());
NTEx = IIf(NT,LastBarExit,0);May 14, 2018 at 9:13 pm #103703AnonymousInactiveExcellent, thanks Julian. I changed it to the below and it seemed to work, I haven’t been through trades to check if it is doing what it is supposed to do yet.
I will add yours too.RSIEx = RSI(14) > 70;
SellSetUp = RSIEx;
LEx = Ref(SellSetUp,-1);Short = Cover = False;
ExitBars = Param(“# Exit Bars”,10,2,100,1);
//=================================================================================
//Looping
//=================================================================================
Buy = 0;
Sell = 0;
PriceAtBuy = 0;
LBIT = 0;
FlagExit = 0;
//=================================================================================for (j = 1; j < BarCount; j++)
{
if (PriceAtBuy==0 AND LE[j])
{
Buy[j] = True;
BuyPrice[j] = LEPrice[j];
PriceAtBuy = BuyPrice[j];
LBIT[j] = 1;if (LBIT[j] > 1 AND (LEx[j] OR OnSecondLastBarOfDelistedSecurity[j]))
{
Sell[j] = True;
SellPrice[j] = Open[j];
PriceAtBuy = 0;
}
}
else
if (PriceAtBuy > 0)
{
LBIT[j] = LBIT[j-1] + 1;
if (LBIT[j] == ExitBars)
{
FlagExit[j] = True;
}if (LBIT[j] > 1 AND (LBIT[j] >= ExitBars OR OnSecondLastBarOfDelistedSecurity[j]))
{
Sell[j] = True;
SellPrice[j] = Open[j];
PriceAtBuy = 0;
}
if (LBIT[j] > 1 AND (LEx[j] OR OnSecondLastBarOfDelistedSecurity[j]))
{
Sell[j] = True;
SellPrice[j] = Open[j];
PriceAtBuy = 0;
}
}
} -
AuthorPosts
- You must be logged in to reply to this topic.