Jump to content
Medved Trader Forums

Cross on multiple indicators

Recommended Posts

I have several indicators to trigger buy and sell points.  The indicators each use two lines.  So when all indicator lines cross in the same direction, it's a buy [or sell].  For example, when a 10 SMA crosses a 20 SMA at the same time as the macd signal crosses the macd main, it could be a buy signal.  The problem is that not all lines cross at the same time: the SMA's may cross a candle or two either before or after the macd lines.  I'd like to be able to have the alert come up even if the crosses are not on the exact same candle.  

In the Scan/paintbar editor there is a setting for "candles ago".  Does that setting apply to the cross specifically N number of candles ago, or does that setting apply to a cross *within* the last N candles?

Link to comment
Share on other sites

Here's a way to do it. Let's say you want to detect it if within 5 candles at least 2 of 3 crosses happened.


You define a FIFOQueue of 15 (5 candles times 3 crosses) capacity. (see https://www.medvedtrader.com/trader/WebHelp/state_keeping.htm - at the bottom of that page - for how to use FIFOQueue in an advanced paintbar or scan)

Then what you do is for each cross you add 1 to the queue if it happened and 0 if it didnt.

The FIFOQueue's Sum property will tell you the result. If it is more than 2, you trigger. If it is less, you don't.


Link to comment
Share on other sites

  • 3 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...