Temporary entry level  [SOLVED]

Questions about MultiCharts and user contributed studies.
User avatar
meras
Posts: 11
Joined: 22 Feb 2022
Has thanked: 2 times
Been thanked: 1 time

Temporary entry level

Postby meras » 06 Aug 2022

I am making the frame for a simple strategy, yet I have problems getting it to work the way I want it to.

Bar color:
I color the bars based on the signals given by indicators. Basically I'm using MACD and RSI. The colors are defined like this:
Green: if both indicators give a long signal
Red: if both indicators give a short signal
Black: if the indicators give different signals (white bars on the chart)
In the attatched file I have used a paintbar indicator to color the bars. The orange lines are drawn using the drawing tools

Here is the part where I struggle:
The entry level for going long is the hight of the first green bar (first orange line in the attached image). If the price crosses the entry level, then it should produce a buying signal.
If the bar color changes to red or black, then the entry level is no longer valid and should be disabled.

I hope the above makes sense. Here is the code I use

Code: Select all

////////////////////////////MACD//////////////////////////// inputs: MACDFastLength( 12 ), MACDSlowLength( 26 ), MACDLength( 9 ) ; variables: MACDsig ( 0 ), MACDAvg( 0 ), MACDDiff( 0 ), MACDLongEntry (true), MACDShortEntry (true), MACDLongExit (true), MACDShortExit (true); MACDsig = MACD( Close, MACDFastLength, MACDSlowLength ) ; MACDAvg = XAverage( MACDsig , MACDLength ) ; MACDDiff= MACDsig - MACDAvg; //MACD Entry MACDLongEntry = MACDDiff crosses over 0; MACDShortEntry = MACDDiff crosses under 0; //MACD Exit MACDLongExit = MACDDiff crosses under 0; MACDShortExit = MACDDiff crosses over 0; ////////////////////////////RSI//////////////////////////// inputs: RSILength (14), RSIOverSold (50), RSIOverBought(50); variables: RSILine( 0 ), RSILongEntry (true), RSIShortEntry (true), RSILongExit (true), RSIShortExit (true); RSILine= RSI( close, RSILength) ; //RSI Entry RSILongEntry = RSILine crosses over RSIOverSold ; RSIShortEntry = RSILine crosses under RSIOverBought; //RSI Exit RSILongExit = RSILine crosses under RSIOverSold ; RSIShortExit = RSILine crosses over RSIOverBought; ////////////////////////////DEFINE BAR COLOR//////////////////////////// vars: setGreenBar (false), setRedBar (false), setBlackBar (false), entryTriggerLong (false), entryLevelLong(0); //Define green bar setGreenBar = MACDLongEntry = true and RSILongEntry = true; //Define red bar setRedBar = MACDLongEntry = false and RSILongEntry = false; //Define black bar setBlackBar = (MACDLongEntry = true or RSILongEntry = true) and (MACDLongEntry = false or RSILongEntry = false); //First Green bar if setGreenBar = true and setGreenBar[1] = false then begin entryLevelLong = High; entryTriggerLong = true; end; if setBlackBar = true or setRedBar = true then begin entryTriggerLong = false; end; ////////////////////////////ENTRY SIGNAL//////////////////////////// //Entry Long if marketposition = 0 and setGreenBar = true and close > entryLevelLong then begin; Buy ( "TestEntry" ) 1 contracts next bar at market ; end; ////////////////////////////EXIT//////////////////////////// if marketposition = 1 and MACDLongExit = true or RSILongExit = true then Sell ( "TestExit" ) 1 contracts next bar at market ;
Note: I dont want to enter the trade on the next bar, but instead when the price breaks above the entry level. I'm quite inexperienced with MC and therefore try to tackle one problem at a time.
Attachments
Entry levels example.jpg
(68.76 KiB) Not downloaded yet

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Temporary entry level

Postby TJ » 06 Aug 2022

If you want to trigger an order intra-bar in real-time,
You need to set IOG IntrabarOrderGeneration to TRUE.

User avatar
meras
Posts: 11
Joined: 22 Feb 2022
Has thanked: 2 times
Been thanked: 1 time

Re: Temporary entry level

Postby meras » 08 Aug 2022

If you want to trigger an order intra-bar in real-time,
You need to set IOG IntrabarOrderGeneration to TRUE.
Thank you. I will keep that in mind when I start working on that :)

User avatar
meras
Posts: 11
Joined: 22 Feb 2022
Has thanked: 2 times
Been thanked: 1 time

Re: Temporary entry level  [SOLVED]

Postby meras » 11 Aug 2022

I have solved the issue using the following:

Code: Select all

//Define first Green if setGreenBar = true and setGreenBar[1] = false then begin entryLevelLong = High; entryLevelDateStart = date; end; //Define last Green if setGreenBar = false and setGreenBar[1] = true then begin entryLevelDateEnd = date[1]; end; entryLine = tl_new(entryLevelDateStart , Time, entryLevelLong, entryLevelDateEnd, Time, EntryLevelLong); tl_setend(entryLine, entryLevelDateEnd, Time, EntryLevelLong); tl_setColor(entryLine, yellow); tl_setsize(entryLine, 1); tl_setstyle(entryLine, 1);
Essentially looking into the trendline properties instead of plot.


Return to “MultiCharts”