sperci0
sperci0

Reputation: 1

How can I enter the trade without waiting for candle closing in Pinescript Strategy?

I have a strategy based on rsi , macd , ema and ADX. I trade with small profit rates. But when the conditions are met, it enters the trade at the close of the candle. I want it to be processed as soon as the conditions occur, like an indicator. How can I do this with codes?

My transaction is reversed because the candle is waiting for the close in the image. How can I make the changes to be processed as they are created?

enter image description here

Upvotes: 0

Views: 1557

Answers (3)

Yann Greder
Yann Greder

Reputation: 71

Okay, it means then, depending on your strategy, it's impossible to have decent data. I created statistics directly into my indicator(). The string can hold maximum 4xxx, this is why I change bool value to 0 or 1.

var string strCSV = "\n DateTime;bubble;bubbleCounter;orderDirection;RRR;hasSLBeenReached;iSWinBe;isBE;hasTargetBeenReached;hasMinTargetBeenReached\n" // ;hasPriceReachedEMA;hasPriceReachedBubbleZoneMult2;hasSMAReachedBubbleZone

bool iSWinBe = (objSetup.SL == objSetup.BE and objSetup.hasMinTargetBeenReached) ? true : false
bool isBE    = (objSetup.SL == objSetup.BE and objSetup.hasMinTargetBeenReached == false) ? true : false

if objSetup.hasTargetBeenReached or objSetup.hasSLBeenReached
    strCSV +=          
         currentTimestamp + ";" + 
         str.tostring(objSetup.bubble) + ";" + 
         str.tostring(objSetup.bubbleCounter) + ";" + 
         str.tostring(objSetup.orderDirection) + ";" + 
         str.tostring(objSetup.RRR, "#.#") + ";" + 
         str.tostring(objSetup.hasLiqBeenReached ? 1 : 0) + ";" + 
         str.tostring(objSetup.hasEntryBeenReached ? 1 : 0) + ";" + 
         str.tostring(objSetup.hasSLBeenReached ? 1 : 0) + ";" + 
         str.tostring(iSWinBe ? 1 : 0) + ";" + 
         str.tostring(isBE ? 1 : 0) + ";" + 
         str.tostring(objSetup.hasTargetBeenReached ? 1 : 0) + ";" + 
         str.tostring(objSetup.hasMinTargetBeenReached ? 1 : 0) + "\n"

It works, the process is slow and heavy.

Upvotes: 0

sperci0
sperci0

Reputation: 1

The situation you mentioned is valid only for " exit " . I'm talking about opening a transaction.

I mentioned using the "once per bar" feature as in the indicator.

Upvotes: 0

vitruvius
vitruvius

Reputation: 21372

You cannot do that on historical bars because only the OHLC information is saved on the historical bars.

For real time trading, you can set calc_on_every_tick argument of the strategy() to true.

calc_on_every_tick (const bool) Specifies whether the strategy should be recalculated on each realtime tick. If true, when the strategy is running on a realtime bar, it will recalculate on each chart update. If false, the strategy only calculates when the realtime bar closes. The argument used does not affect strategy calculation on historical data. This setting can also be changed in the strategy's "Settings/Properties" tab. Optional. The default is false.

Upvotes: 1

Related Questions