[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: Bar by bar multiple criteria buy & sell signals.



PureBytes Links

Trading Reference Links



Hello,

Here is the code of my problem, I am not a very nice programmer so please kindly adjust, what I am trying to do is to have multiple criteria defined for buy and sell signals.

I have multiple candle stick patterns MORNING START, ENGULFING BULL, KICKER etc defined in AFL with combination of multiple indicators, MACD, RSI, ADX etc.

For now BuyEvent1, BuyEvent2, BuyEvent3 and BuyEvent4 are the defined buy signals.

Same with sell, SellEvent1, SellEvent2, SellEvent3 and SellEvent4 are the 4 different criteria for sell signal.

Behind these variables the buy and sell signals are defined.

/////

BuySignal = (BuyEvent1) OR (BuyEvent2) OR (BuyEvent3) OR (BuyEvent4);

SellSignal = (SellEvent1) OR (SellEvent2) OR (SellEvent3) OR (SellEvent4);

//Only one of these buy or sell signal should be applicable for any bar.

/////

Now for generating signals, instead of using flat signal criteria and then removing excessive signals by using ExRem, I have to keep track of each signal since each signal might be of any criteria defined above.  So I am using a loop and check status of last signal (buy/sell), If there wasn't any buy signal earlier then no sell signal will be generated. Same for sell signal.

/////

Sell = 0;

Buy = 0;

BP =0;    //Buy Price

SP =0;    //Sell Price

BuyACTION = 0;   //Individual Buy Action

SellACTION = 0;  //Individual Sell Action  

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

{

global X;

X = Cum(BuySignal);     //Total number of buy signals.

global BP;   

global SP;   

global Y;

global U;

global Z;

SP = 0;

BP = 0;

LastSignal = 0;  //Keep track of last signal type, Buy or Sell. 0 = initial, 1 = buy, 2 = sell.

Z = 1;    //Buy signal counting, starting from 1. 

U = 1;    //Sell signal counting strating from 1.

//Define first buy signal

if(  X[i] == z AND LastSignal[i] == 0)

   {

   BuyACTION[i] = BuySignal[i];

   ExRemSpan( BuyACTION, SellACTION);

   Lastsignal = 1;

   Z++;

if (BuyACTION[i]){ BP = ValueWhen (BUYACTION,BuyPrice);}

   }

else { BuyACTION[i] = 0 AND Lastsignal = 0;}

 

//Check if a buy signal was defined earlier and then define first sell signal

if(  X[i] == U AND  LastSignal[i] == 1)

   {  

   SellACTION[i] = SellSignal[I];

LastSignal = 2;

SellACTION = ExRem(SellACTION,BuyACTION);

   if (SELLEVENT[i]){ SP = ValueWhen(SellACTION,SellPrice);}

   BuyBarPlus2[i] = BarsSince(BuyACTION) >=2;  

   //Start sell signal after 2 bars from buy signal.

   }

else {Lastsignal = 0 AND SellACTION[i] = 0;}

 

//Check if a sell signal was defined earlier and then define next buy signal

if(  X[i] == z AND Lastsignal[i] == 2)

   {

   BuyACTION[i] = BuySignal[i];

   Lastsignal = 1;

   BuyACTION = ExRem(BuyACTION,SellACTION);

   Z++; U++;

if (BuyACT[i]){global BP; BP = ValueWhen (BUYACT,BuyPrice);}

   }

else { LastSignal = 0;}

//Check if a buy signal was defined earlier and then define next sell signal

if(  X[i] == U AND  LastSignal[i] == 1)

   {

SellACTION[i] = SellSignal[i];

   SellACTION = ExRem(SellACTION,BuyACTION);

       Lastsignal = 2;     

   if (SellSignal[i]){ SP = ValueWhen(SellACTION,SellPrice);}

   BuyBarPlus2[i] = BarsSince(BuyACTION) >=2;  

   //Start sell signal after 2 bars from buy signal.

   }

else {LastSignal = 1; }

}

Buy = BuyACTION;

Sell = BuyBarPlus2 AND SellACTION;

After this just for visual presentation, I plot shapes, prices and assign number to each signal. Variables like BP, SP are used in plotting.  Eveyting is ok in that.

The problem is, for both buy and sell signal the system continues to use the very first criteria met, for example if the first buy signal was with BuyEvent3 then all buy signals are of BuyEvent3 criteria, and if the first sell signal was of SellEvent1 then all next sell signals are of SellEvent1 criteria. My purpose for each bar selecting any one of multiple criteria defined dosent get fulfilled.

I tried to keep the code short and relevant to post here.

How to fix it?

Thanks

 

 

 

 


--- In amibroker@xxxxxxxxxxxxxxx, "markedme9" <markedme9@xxx> wrote:
>
>
> Hi,
>
> How to generate buy/sell signals using multiple criteria, I need 4
> different criteria for both buy and sell signals.
>
>
> Buy signal can be based on MACD, ADX, RSI or MA etc. And the sell signal
> after this buy signal can be of any of these indicators,
> For example, If buy was from MACD then sell is from ADX, if buy from RSI
> then sell from MACD indicator.
>
> For each buy or sell, at every bar the system should check for all four
> criteria and select only one specific to that bar number. For bars
> ahead, it might find other suitable criteria.
>
> I have been trying it with "logical OR", by looping "(i=0;
> i<barcount;i++)", by "switch" loop, by "while,
> break" loop, using array element [].
>
> It doesn't seem to work. What it dose is, whenever it meets first
> criteria, its using just that criteria through out, till BarCount. If
> first buy was found by RSI then all next buy signals are from RSI, it
> won't consider MACD or DAX or anything else to find next buy signal.
>
>
>
> Anyone tried doing this?
>
>
>
> Thanks
>



__._,_.___


**** 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/





Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___