Jump to content
Medved Trader Forums

Crypto

Members
  • Content count

    9
  • Joined

  • Last visited

Everything posted by Crypto

  1. Yes that works - ty. So here is the complete example working code if anyone is trying to do the same thing: public void MainCalculation() { if (!CurrentState.InTrade && (Close > Low[1]) ) { SetColor(SysColor.Positive); SetShape(PBShape.ArrowRight); CurrentState.InTrade = true; return; } if (CurrentState.InTrade && (Close < Close[1]) ) { SetColor(SysColor.Bid); SetShape(PBShape.Star); CurrentState.InTrade = false; return; } } /// <summary> /// Is called at start of paintbar calculation, should be used to initialize anything needed for the paintbar /// </summary> private void PaintbarInitialize() { CurrentState.InTrade = false; } /// <summary> /// Holds paintbar state - fill with variables needed to be preserved for next paintbar calc /// </summary> private struct PaintbarState { public Boolean InTrade; } /// <summary> /// Holds current PB state - use to calc PB, changes to it carry over to next PB calc /// </summary> private PaintbarState CurrentState; /// <summary> /// Holds saved PB state - internal /// </summary> private PaintbarState SavedState; /// <summary> /// Is called at start of paintbar calculation, should be used to clear the paintbar state /// </summary> private void PaintbarClearState() { CurrentState = new PaintbarState(); } /// <summary> /// Saves paintbar state (called internally). /// </summary> private void PaintbarSaveState() { SavedState = CurrentState; } /// <summary> /// Restores paintbar state (called internally). /// </summary> private void PaintbarRestoreState() { CurrentState = SavedState; }
  2. Hi forum I'm new to Medved Trader (not new to trading). I'm experimenting with the Intraday charts and have created a number of paintbars which are appearing on the chart. I've looked at the YouTube tutorials and documentation and can't seem to find what I'd like to do. Is it possible to link the paintbars so they only fire/appear on the intraday chart if the other paintbar conditions equate to true. For example I have a buy paintbar called b_p and a sell paintbar called s_p. Can I set up the paintbars so 's_p' only appears after 'b_bp' appears and then once 's_p' appears 'b_bp' can trigger again ? Not sure if that's clear, currently on my intraday chart I have many consecutive 'buy' signal and 'sell' signals and I only want to see alternating signals buy sell buy sell buy sell etc Cheers
  3. I tried that initially however I was still getting an error in the Initialize section with 27, 5 CS0103 The name 'InTrade' does not exist in the current context So I deleted the InTrade = false; in PaintbarInitialize (assuming there is some sort of internal initialization anyway) and now I think it works will check thoroughly now. So now I'm getting the desired behavior in terms of buy sell buy sell etc. Just need to work on my rules now : Thanks Jerry !!
  4. Yes, thanks that's exactly what I want to do and I understand the logic, here's the code as it stands: I'm getting a compile error for this statement in the struct: public Boolean InTrade = false; Error says: CS0573 'MT.Charting.RUNTIME.Paintbar_C_06.PaintbarState.InTrade': cannot have instance field initializers in structs Googling this I'm reading you can't initialize in Structs maybe ? If I try to remove the '=false' in the private struct PaintbarState I get the error CS0103 The name 'InTrade' does not exist in the current context public void MainCalculation() { if (!CurrentState.InTrade && (Close > Low[1]) ) { SetColor(SysColor.Positive); SetShape(PBShape.ArrowRight); TriggerAlert("Buy01"); CurrentState.InTrade = true; return; } if (CurrentState.InTrade && (Close < Close[1]) ) { SetColor(SysColor.Bid); SetShape(PBShape.Star); CurrentState.InTrade = false; return; } } /// <summary> /// Is called at start of paintbar calculation, should be used to initialize anything needed for the paintbar /// </summary> private void PaintbarInitialize() { InTrade = false; } /// <summary> /// Holds paintbar state - fill with variables needed to be preserved for next paintbar calc /// </summary> private struct PaintbarState { public Boolean InTrade = false; } /// <summary> /// Holds current PB state - use to calc PB, changes to it carry over to next PB calc /// </summary> private PaintbarState CurrentState; /// <summary> /// Holds saved PB state - internal /// </summary> private PaintbarState SavedState; /// <summary> /// Is called at start of paintbar calculation, should be used to clear the paintbar state /// </summary> private void PaintbarClearState() { CurrentState = new PaintbarState(); } /// <summary> /// Saves paintbar state (called internally). /// </summary> private void PaintbarSaveState() { SavedState = CurrentState; } /// <summary> /// Restores paintbar state (called internally). /// </summary> private void PaintbarRestoreState() { CurrentState = SavedState; }
  5. Maybe an example will explain better. I have a rule (my Buy signal), my conditional logic, that I think will be an entry point for a long trade and I also have another rule that I want to use as my exit, ie when I want to sell. My sell logic will hopefully tell me to either exit for a good profit or get out of a bad trade, my stop loss rule. So let's say I enter a BTCUSD trade: 5/Feb I buy BTC @ 6912 USD 6th to 16th Feb my BUY rule may trigger/equate to TRUE again and again - but I don't care because I'm already in the trade. The only rule/code I'm interested in now is my SELL rule. My sell rule will either stop me out or tell me to exit on the 17th of Feb for a profit. Now that I'm out of that trade, I now want to display the next BUY rule hit because I want to get into another trade so I don't care about my SELL rule right now because I'm not in a trade. That's why I thought I needed 2 paintbars however I couldn't work out how I could determine in my SELL paintbar if the BUY had been triggered. Once a Buy is triggered, I don't want to see any more BUYs on my chart. This is a daily example, however I want to do this on the Intraday chart. I've drawn Green for buy and Red for SELL.
  6. Thanks Jerry, However that doesn't work for what I want to do. I haven't been able to communicate what I'm trying to achieve. If I remove the returns I get a combination of buy buy buy sell sell sell or buy sell. etc. If t represents time I want to do this: Buy t1 t2 t3 t4 Sell t4 t5 t6 t7 t8 Buy etc In other words a Sell can't appear unless a Buy has occurred in the past and a Buy can't appear unless a Sell has occurred in the past. Let's leave it at that for this thread, I appreciate your replies. Cheers
  7. I'm trying Jerry ... so here's a simple example below. gBuy1 is my boolean variable to indicate a buy My first IF is my Buy rule - it works and appears on the chart My second IF is my Sell rule - I check if gBuy1 is true and if my sell condition is true, set color/shape and clear my gBuy1 signal (set to false) so my first IF can be executed. My second IF never executes. If I remove the boolean gBuy1 it executes and shows on my intraday however this is not what I want. Is the boolean defined (gBuy1) in this paintbar persistent every time period or am I doing something else wrong ? I'm close, I feel it public void MainCalculation() { Boolean gBuy1 = false; if ((!gBuy1) && (Close > Low[1]) ) { SetColor(SysColor.Positive); SetShape(PBShape.ArrowRight); TriggerAlert("Buy01"); gBuy1 = true; return; } if (gBuy1 && (Close < Close[1]) ) { SetColor(SysColor.Bid); SetShape(PBShape.Star); gBuy1 = false; return; } }
  8. Thanks Jerry, I made the mistake of thinking the simple paintbar conditions all made up a logical AND and realised they don't Ok thanks for the tip re adding the variables in simple editor first and then converting to advanced as it certainly makes things easier whilst I'm new to this app. I've created some paintbars using the advanced editor and they're behaving as expected. I'll try the triggers now - I assume the triggers are visible only within the scope of the current paintbar and not in another paintbar I create ? That would be ideal for me so I can code a buy paintbar which sets a trigger and check if it's true in my sell paintbar. I'll experiment now. Cheers
  9. Hi Jerry Do you mean something like TriggerAlert(String AlertName, String Message) ? So if I had a Buy indicator and my conditions evaluated to true I would code something like this: TriggerAlert('TradeAlert', 'BUY') and then in my SELL indicator - how would I reference that alert - if TradeAlert = 'BUY' { //set another alert} ?? Alternatively can i use in the Simple paintbar editor set the Alert, Name it and create a message like below ? And how can I reference that alert in another paintbar ? Sorry for all the Q's, I'm struggling with this at the moment. Crypto
×