Strategy Condition (2nd bar close above/below condition) - if-statement

I am literally brand new to pine script and have stumbled my way to this point but I really am stumped. Thanks in advance for any direction.
I am trying to create a simple strategy around EMA/SMA. I am looking to force the strategy to not take the long or short exit unless exitcondition(long&short)1 has 2 consecutive closes below/above the condition defined. The strategy is working as intended otherwise but I was hoping I would be able to add this variable to test different setups.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © bubblyApple52984
//#version=5
strategy("EMA strategy", overlay=true, process_orders_on_close = true, margin_long=100, margin_short=100)
ema_input1 = input.int(1, "Fast")
ema_input2 = input.int(2, "Slow")
sma_input3 = input.int(3, "SuperSlow")
plot(ta.ema(close, ema_input1),"fast",color.green)
plot (ta.ema(close, ema_input2),"slow",color.white)
plot (ta.sma(close, sma_input3), "superslow",color.red)
shortCondition1 = close < ta.sma(close, sma_input3)
shortCondition2 = ta.crossunder(ta.ema(close, ema_input1), ta.ema(close, ema_input2))
shortCondition3 = ta.ema(close,ema_input1) < ta.sma(close, sma_input3)
shortCondition4 = ta.ema(close,ema_input2) < ta.sma(close, sma_input3)
exitConditionShort1 = close >= ta.ema(close, ema_input2)
//exitConditionShort2 = ta.crossover(ta.ema(close, ema_input1), ta.ema(close, ema_input2))
inTradeShort = strategy.position_size < 0
if (shortCondition1 and shortCondition2 and shortCondition3 and shortCondition4)
strategy.entry("My Short Entry Id", strategy.short)
if (exitConditionShort1 and inTradeShort)
strategy.close(id="My Short Entry Id", comment="CloseShort")
longCondition1 = close > ta.sma(close, sma_input3)
longCondition2 = ta.crossover(ta.ema(close, ema_input1), ta.ema(close, ema_input2))
longCondition3 = ta.ema(close,ema_input1) > ta.sma(close, sma_input3)
longCondition4 = ta.ema(close,ema_input2) > ta.sma(close, sma_input3)
exitConditionlong1 = close <= ta.ema(close, ema_input2)
//exitConditionlong2 = ta.crossunder(ta.ema(close, ema_input1), ta.ema(close, ema_input2))
inTradelong = strategy.position_size > 0
if (longCondition1 and longCondition2 and longCondition3 and longCondition4)
strategy.entry("My Long Entry Id", strategy.long)
if (exitConditionlong1 and inTradelong)
strategy.close(id="My Long Entry Id", comment="CloseLong")
This is what I have and it works but it completes the "strategy.close" off the 1st candle close above/below the ema_input2. I need help making this strategy close the position based on the 2nd consectutive bar close above/below the ema_input2.
Thanks

You could try with the previous value of exitConditionShort1, and the current value
Something like that
if (exitConditionShort1 and exitConditionShort1[1] and inTradeShort)
strategy.close(id="My Short Entry Id", comment="CloseShort")

Related

Pine Script - Exit When Open Price > Entry Price "aka first profitable open"

Thank you once again in advance for your assistance.
Trying to get market order to execute at first profitable open
As recommended, tried several 'process_orders_on_close'. Set to true, fixes original problem of exiting one bar late (perfect!) But, it breaks the entry, first image below, in that entry is on condition as opposed to bar after condition is met. Image One below.
[![Image One][1]][1]
For image two, the intent was to toggle 'process_orders_on_close' from "na" to "true". Fixed entry but original problem exiting one bar late returns. Results and code in Image Two below.
[![Image Two][2]][2]
Thank you once again.
//CODE FOR IMAGE ONE
//#version=4
strategy(title="Pattern Tester - FPO)", process_orders_on_close = true,
overlay=true)
OS = (high > high[1] and low < low[1] and close < close[1])
if (OS)
process_orders_on_close = true, strategy.entry(id="FPO", long=true)
if strategy.position_size > 0
strategy.close("FPO", when = open > strategy.position_avg_price)
//CODE FOR IMAGE TWO
//#version=4
strategy(title="Pattern Tester - FPO)", process_orders_on_close = na,
overlay=true)
OS = (high > high[1] and low < low[1] and close < close[1])
if (OS)
strategy.entry(id="FPO", long=true)
if strategy.position_size > 0
process_orders_on_close = true, strategy.close("FPO", when = open > strategy.position_avg_price)
[1]: https://i.stack.imgur.com/4VLcQ.jpg
[2]: https://i.stack.imgur.com/LcXsZ.jpg
You can use ``` before and after your code for monospace.
You can use process_orders_on_close=true with your strategy() declaration statement.

NetSuite - error closing return authorization using web services

Within NetSuite when trying to close out Return Authorization line items i receive the following error message:
INSUFFICIENT_PERMISSION
"You do not have permissions to set a value for element item.quantityreceived due to one of the following reasons: 1) The field is read-only; 2) An associated feature is disabled; 3) The field is available either when a record is created or updated, but not in both cases."
Here is the code:
//Pull down the RA in order to work with the line items in question
RecordRef rec = new RecordRef();
rec.internalId = internalId;
rec.type = RecordType.returnAuthorization;
rec.typeSpecified = true;
ReadResponse response = _service.get(rec);
//create the object from the response record returned
ReturnAuthorization ra = (ReturnAuthorization)response.record;
//cancel the order by updating the qty of each item to zero.
WriteResponse res = null;
ReturnAuthorizationItem[] raItemList = ra.itemList.item;
for (int lineCounter = 0; lineCounter < raItemList.Length; lineCounter++)
{
//only if the qty received is zero are we closing out the item(setting qty to zero)
if (raItemList[lineCounter].quantityReceived == 0)
{
raItemList[lineCounter].quantity = 0;
raItemList[lineCounter].quantitySpecified = true;
}
}
//create a new object and add all the changes in order to update the order lines
ReturnAuthorization updRa = new ReturnAuthorization();
updRa.internalId = internalId;
updRa.itemList = new ReturnAuthorizationItemList();
updRa.itemList.item = new ReturnAuthorizationItem[raItemList.Length];
updRa.itemList.item = raItemList;
res = _service.update(updRa);
I am trying to update the line quantity to zero, which in affect will close the Return Authorization if everything has been zeroed out. Question is how do i correct this permissions issue in order to run this update. I have tried setting other fields on this same call. No matter which field i try and update i get the same error message. This is running under an admin account and all permissions look fine as far as i can see. In fact i am running this very same logic against the SaleOrder object to close out Sales Orders with no issues.
Any help would be much appreciated.
Thanks,
Billy
You can't directly edit that line item field. That field is maintained by Netsuite and reflects Item Receipts received against the RA.
If you want to close the RA without receiving just set the line item column field "Closed" to true.
After looking at this a little closer here is the solution:
Replace the if statement in the loop with this:
//only if the qty received and returned are zero do we close out the item(setting qty to zero)
if (raItemList[lineCounter].quantityReceived == 0 && raItemList[lineCounter].quantityBilled == 0)
{
raItemList[lineCounter].quantity = 0;
raItemList[lineCounter].quantitySpecified = true;
raItemList[lineCounter].isClosed = true;
raItemList[lineCounter].isClosedSpecified = true;
raItemList[lineCounter].quantityReceivedSpecified = false;
raItemList[lineCounter].quantityBilledSpecified = false;
raItemList[lineCounter].costEstimateSpecified = false;
}
else
{
raItemList[lineCounter].quantityReceivedSpecified = false;
raItemList[lineCounter].quantityBilledSpecified = false;
raItemList[lineCounter].costEstimateSpecified = false;
}
I am guessing that the fields i had to specific as false are fields that cannot be edited, hence the need to disclude them from the update.
This is a better sample. Note the comment re orderline
/Pull down the RA in order to work with the line items in question
RecordRef rec = new RecordRef();
rec.internalId = internalId;
rec.type = RecordType.returnAuthorization;
rec.typeSpecified = true;
ReadResponse response = _service.get(rec);
//create the object from the response record returned
ReturnAuthorization ra = (ReturnAuthorization)response.record;
//cancel the order by updating the qty of each item to zero.
WriteResponse res = null;
ReturnAuthorizationItem[] raItemList = ra.itemList.item;
ReturnAuthorization updRa = new ReturnAuthorization();
updRa.internalId = internalId;
updRa.itemList = new ReturnAuthorizationItemList();
ReturnAuthorizationItem[] updateItems = new ReturnAuthorizationItem[raItemList.Length];
for (int lineCounter = 0; lineCounter < raItemList.Length; lineCounter++)
{
updateItems[lineCounter].line = raItemList[lineCounter].line; // you'll need to test this. Setting only the line should result in no changes to the RA line items that are not to be closed. use the &xml=T view before and after to make sure orderline (hidden) is still populated properly.
//only if the qty received is zero are we closing out the item(setting qty to zero)
if (raItemList[lineCounter].quantityReceived == 0)
{
updateItems[lineCounter].isClosed = true;
// raItemList[lineCounter].quantitySpecified = true; // is quantitySpecified a field? it wasn't as of the 2012.2 endpoint
}
}
//create a new object and add all the changes in order to update the order lines
updRa.itemList.item = updateItems;
res = _service.update(updRa);

Ruby on Rails factoring help conditional

I'm working with pull review and asks me to factor the following code, someone can help me with this?
#start_time = (params[:start_time].to_time.hour.to_i < #room.opening_time.hour.to_i)? #room.opening_time.hour_minutes : params[:start_time]
#end_time = (params[:end_time].to_time.hour.to_i > #room.closing_time.hour.to_i)? #room.closing_time.hour_minutes : params[:end_time]
To start you could throw some of the crazy long chains you're comparing into variables like so
opening_time = #room.opening_time.hour.to_i
closing_time = #room.closing_time.hour.to_i
starting_time = params[:start_time].to_time.hour.to_i
ending_time = params[:end_time].to_time.hour.to_i
open_minutes = #room.opening_time.hour_minutes
close_minutes = #room.closing_time.hour_minutes
Then you can do
#start_time = starting_time < opening_time ? start_minutes : params[:start_time]
#end_time = ending_time > closing_time ? end_minutes : params[end_time]
Which is a lot more readable.
From there I would recommend extracting out to two methods to run the actual conditionals, to make it clearer in English what the code is trying to do. For example:
def get_start_time(time)
starting_time = time.to_time.hour.to_i
opening_time = #room.opening_time.hour.to_i
open_minutes = #room.opening_time.hour_minutes
starting_time < opening_time ? start_minutes : time
end
def get_end_time(time)
ending_time = time.to_time.hour.to_i
closing_time = #room.closing_time.hour.to_i
close_minutes = #room.closing_time.hour_minutes
ending_time > closing_time ? end_minutes : time
end
#start_time = get_start_time(params[:start_time])
#end_time = get_end_time(params[:end_time])
Which, while it may be more physical code, is a lot clearer and simpler to read, which is a huge part of refactoring, especially when working with a group.

Python error pop up not working

Writing code and I broke it somehow and can't remember what was previously working, only been using python a few weeks and after working on this literally all day, I'm more than a little frustrated...
# A program to calculate delivery order totals
from graphics import *
#Error Window
def errorWindow():
errwin = GraphWin("Error", 200, 200)
errwin.setCoords(0.0, 0.0, 4.0, 4.0)
errwin.setBackground(color_rgb(33,158,87))
Text(Point(2, 3), "This is not a valid order").draw(errwin)
Text(Point(2, 2.5), "Please try again").draw(errwin)
outline = Rectangle(Point(1.5,1), Point(2.5,2))
outline.setFill('white')
outline.draw(errwin)
okbutton = Text(Point(2,1.5),"OK")
okbutton.draw(errwin)
done=errwin.getMouse()
if (done.getX() > 1.5 and done.getX() < 2.5):
errwin.close()
def main():
win = GraphWin("Brandi's Bagel House", 500, 500)
win.setCoords(0.0, 0.0, 10.0, 10.0)
win.setBackground(color_rgb(33,158,87))
#Banner
banner = Rectangle(Point(0, 8), Point(10, 10))
banner.setFill(color_rgb(97,76,26))
banner.setOutline(color_rgb(97,76,26))
banner.draw(win)
#Logo Image
circ = Circle(Point(1,9), .65)
circ.setFill('white')
circ.setOutline('white')
circ.draw(win)
circ2 = Circle(Point(1,9), .6)
circ2.setFill(color_rgb(33,158,87))
circ2.setOutline(color_rgb(33,158,87))
circ2.draw(win)
bigb = Text(Point(1, 9),"B")
bigb.setStyle('bold italic')
bigb.setTextColor('white')
bigb.setFace('courier')
bigb.setSize(28)
bigb.draw(win)
#Horizontal Lines
Line(Point(0,2.25), Point(10,2.25)).draw(win)
Line(Point(0,4.25), Point(10,4.25)).draw(win)
Line(Point(0,6.25), Point(10,6.25)).draw(win)
#Text
title = Text(Point(4,9), "Delivery Orders:")
title.setSize(20)
title.setTextColor('white')
title.draw(win)
Text(Point(1.5,7), "Bagels:").draw(win)
whitetext = Text(Point(3,7.5), "White")
whitetext.setSize(10)
whitetext.draw(win)
wheattext = Text(Point(5,7.5), "Wheat")
wheattext.setSize(10)
wheattext.draw(win)
Text(Point(1.5,5), "Toppings:").draw(win)
creamtext = Text(Point(3,5.8), "Cream")
creamtext.setSize(10)
creamtext.draw(win)
cheesetext = Text(Point(3,5.5), "Cheese")
cheesetext.setSize(10)
cheesetext.draw(win)
buttertext = Text(Point(5,5.5), "Butter")
buttertext.setSize(10)
buttertext.draw(win)
jellytext = Text(Point(7,5.5), "Jelly")
jellytext.setSize(10)
jellytext.draw(win)
Text(Point(1.5,3), "Coffee:").draw(win)
regtext = Text(Point(3,3.5), "Regular")
regtext.setSize(10)
regtext.draw(win)
decaftext = Text(Point(5,3.5), "Decaf")
decaftext.setSize(10)
decaftext.draw(win)
Text(Point(7,1.5), "Subtotal:").draw(win)
Text(Point(7,1), "Tax:").draw(win)
Text(Point(7,0.5), "Total:").draw(win)
#input bagel
bagel1 = Entry(Point(3,7), 3)
bagel1.setText("0")
bagel1.draw(win)
bagel2 = Entry(Point(5,7), 3)
bagel2.setText("0")
bagel2.draw(win)
#input topping
top1 = Entry(Point(3,5), 3)
top1.setText("0")
top1.draw(win)
top2 = Entry(Point(5,5), 3)
top2.setText("0")
top2.draw(win)
top3 = Entry(Point(7,5), 3)
top3.setText("0")
top3.draw(win)
#input coffee
coff1 = Entry(Point(3,3), 3)
coff1.setText("0")
coff1.draw(win)
coff2 = Entry(Point(5,3), 3)
coff2.setText("0")
coff2.draw(win)
#Calculate Button
outer1 = Rectangle(Point(4.2,0.6), Point(5.8,1.4))
outer1.setFill('white')
outer1.draw(win)
button = Text(Point(5,1),"Calculate")
button.draw(win)
#Quit Buttons
outer2 = Rectangle(Point(9,9.2), Point(9.95,9.95))
outer2.setFill('white')
outer2.draw(win)
button = Text(Point(9.5,9.6),"Quit")
button.draw(win)
#Output
subtotaloutput = Text(Point(9,1.5), "$0.00")
subtotaloutput.draw(win)
taxoutput = Text(Point(9,1), "$0.00")
taxoutput.draw(win)
totaloutput = Text(Point(9,0.5), "$0.00")
totaloutput.draw(win)
#calculations
whitebagel = eval(bagel1.getText())
whitetotal = whitebagel* 1.25
wheatbagel = eval(bagel2.getText())
wheattotal = wheatbagel*1.50
creamcheese = eval(top1.getText())
creamtotal = creamcheese* 0.50
butter = eval(top2.getText())
buttertotal = butter*0.25
jelly = eval(top3.getText())
jellytotal = jelly*0.75
regularcoff = eval(coff1.getText())
regulartotal = regularcoff*1.25
decafcoff = eval(coff2.getText())
decaftotal = decafcoff*1.25
click = win.getMouse()
if (click.getX() > 4.2 and click.getX() < 5.8 and (whitebagel >0 or wheatbagel >0)):
subtotal = whitetotal+wheattotal+creamtotal+buttertotal+jellytotal+regulartotal+decaftotal
tax = .06
taxes = subtotal*tax
total = taxes+subtotal
subtotal = "$%0.2f" % (subtotal)
taxes = "$%0.2f" % (taxes)
total = "$%0.2f" % (total)
subtotaloutput.setText(subtotal)
taxoutput.setText(taxes)
totaloutput.setText(total)
#Coffee Cup Image
bottomoval = Oval(Point(0.7,0.4), Point(1.4, 0.7))
bottomoval.setFill(color_rgb(97,76,26))
bottomoval.setOutline(color_rgb(97,76,26))
bottomoval.draw(win)
cup = Rectangle(Point(0.7,0.5), Point(1.4,1.3))
cup.setFill(color_rgb(97,76,26))
cup.setOutline(color_rgb(97,76,26))
cup.draw(win)
topoval = Oval(Point(0.6,1.2), Point(1.5, 1.5))
topoval.setFill('white')
topoval.setOutline(color_rgb(97,76,26))
topoval.draw(win)
coffee = Oval(Point(0.7,1.26), Point(1.4, 1.45))
coffee.setFill(color_rgb(71,54,14))
coffee.setOutline(color_rgb(71,54,14))
coffee.draw(win)
tinycirc = Circle(Point(1.05,0.8), .3)
tinycirc.setFill(color_rgb(33,158,87))
tinycirc.setOutline('white')
tinycirc.draw(win)
letter = Text(Point(1.05,0.8),"B")
letter.setStyle('bold italic')
letter.setTextColor('white')
letter.setFace('courier')
letter.setSize(17)
letter.draw(win)
#Bagel
outerbagel = Oval(Point(1.8, 0.4), Point(2.7, 1))
outerbagel.setFill(color_rgb(191,157,61))
outerbagel.draw(win)
shadow = Oval(Point(2.1, 0.7), Point(2.4, 0.8))
shadow.setFill(color_rgb(130,102,26))
shadow.draw(win)
elif(click.getX() > 4.2 and click.getX() < 5.8 and whitebagel <1 and wheatbagel <1):
errorWindow()
#End
point = win.getMouse()
if (point.getX() > 9 and point.getX() < 9.95):
win.close()
main()
I need an error window to pop up if bagels are not selected with an order, as for this example coffee and toppings are not available for delivery without bagels. I think I previously had this in a try/except, but now I can't get that to work either. Either it won't calculate the totals and pops up or it calculates but still pops up the error, or nothing happens! I also can't seem to find any direction on after closing the pop up, to go back to a functioning main window. When I do close out the error window, the main window no longer works. I'd like to be able to do that. Lastly I cannot use tkinter, only graphics.py. I also apologize if anything is crudely done, so far it's the only way I know. Thanks in advance for any advice.
I am still hoping someone will take pity on me and give me some direction as to where I'm going wrong with this code... I have changed the part I'm having issues with but it's still not working:
try:
click = win.getMouse()
if click.getX() > 4.2 and click.getX() < 5.8 and whitebagel >0 and wheatbagel >0:
subtotal = whitetotal+wheattotal+creamtotal+buttertotal+jellytotal+regulartotal+decaftotal
tax = .06
taxes = subtotal*tax
total = taxes+subtotal
subtotal = "$%0.2f" % (subtotal)
taxes = "$%0.2f" % (taxes)
total = "$%0.2f" % (total)
subtotaloutput.setText(subtotal)
taxoutput.setText(taxes)
totaloutput.setText(total)
#Coffee Cup Image
bottomoval = Oval(Point(0.7,0.4), Point(1.4, 0.7))
bottomoval.setFill(color_rgb(97,76,26))
bottomoval.setOutline(color_rgb(97,76,26))
bottomoval.draw(win)
cup = Rectangle(Point(0.7,0.5), Point(1.4,1.3))
cup.setFill(color_rgb(97,76,26))
cup.setOutline(color_rgb(97,76,26))
cup.draw(win)
topoval = Oval(Point(0.6,1.2), Point(1.5, 1.5))
topoval.setFill('white')
topoval.setOutline(color_rgb(97,76,26))
topoval.draw(win)
coffee = Oval(Point(0.7,1.26), Point(1.4, 1.45))
coffee.setFill(color_rgb(71,54,14))
coffee.setOutline(color_rgb(71,54,14))
coffee.draw(win)
tinycirc = Circle(Point(1.05,0.8), .3)
tinycirc.setFill(color_rgb(33,158,87))
tinycirc.setOutline('white')
tinycirc.draw(win)
letter = Text(Point(1.05,0.8),"B")
letter.setStyle('bold italic')
letter.setTextColor('white')
letter.setFace('courier')
letter.setSize(17)
letter.draw(win)
#Bagel
outerbagel = Oval(Point(1.8, 0.4), Point(2.7, 1))
outerbagel.setFill(color_rgb(191,157,61))
outerbagel.draw(win)
shadow = Oval(Point(2.1, 0.7), Point(2.4, 0.8))
shadow.setFill(color_rgb(130,102,26))
shadow.draw(win)
except:
errorWindow()
I think i'm losing my mind here with the amount of time I've been trying to get this to work...
First, tkinter is not the way to go with graphics. It is kinda old and a lot of the concepts there will not turn out to be portable. Then again, use it if there is no other option...
Second, the code for ErrorWindow is not properly indented. When it is, I get at least one error popup. Possibly not in the right error condition.
Third, I would put some sort of check for the Y coordinates of the click as well, since you can trigger the Calculate button by clicking anywhere in its vertical column, like say the wheat text box.
Usually with a GUI there is some sort of event loop for processing multiple clicks. Something like:
while(True):
click = win.getMouse()
if calculate button:
get text values
if not bagels:
errorWindow()
continue
calculate
elif quit button:
break
I made a modified version that had an event loop structured this way and I got it to give multiple totals, as well as putting up an error when I had no bagel order and then keeping going.

How to disable automatic creation SeriesCollection in Excel Chart

I have already this code
Excel::_ApplicationPtr app("Excel.Application");
app->Visible[0] = false;
Excel::_WorkbookPtr book = app->Workbooks->Add();
Excel::_WorksheetPtr sheet = book->Worksheets->Item[1];
RangePtr pRange = sheet->Cells;
RangePtr pCell;
pCell = pRange->Item[1][1]; // A1
pCell->Value2 = "1";
pCell = pRange->Item[1][2]; // B1
pCell->Value2 = "1";
pCell = pRange->Item[1][3]; // C1
pCell->Value2 = "10";
pCell = pRange->Item[2][1]; // A2
pCell->Value2 = "3";
pCell = pRange->Item[2][2]; // B2
Cell->Value2 = "1";
pCell = pRange->Item[2][3]; // C2
pCell->Value2 = "20";
and next
Excel::RangePtr pBeginRange = pRange->Item[1][1];
Excel::RangePtr pEndRange = pRange->Item[5][9];
Excel::RangePtr pTotalRange = sheet->Range[(Excel::Range *)pBeginRange][(Excel::Range *)pEndRange];
_ChartPtr pChart2 = book->Charts->Add();
pChart2->ChartType = xlBubble3DEffect;
pChart2->SetSourceData((Excel::Range *)pTotalRange, (long)Excel::xlColumns);
How to disable automatic creation SeriesCollection in Excel Chart. I want to set the ranges manually. In the automatic creation all SeriesCollection has XValues in the first column. But I needn't it.
I've come across the same issue as well. From experimentation I think the following is happening:
When you create a new chart in VBA using the following code
Dim chSheet As Chart
Set chSheet = Charts.Add
Excel, trying to be helpful I bet, automatically looks at which ever worksheet your cursor had selected when you executed your code from the developer window and searches for the nearest dataset it thinks could be a range of values for the graph. This is then automatically populated in the graph. The only way around it I've found so far is to execute the following code to delete all series objects in the series collection object on the chart immediately after having created it. Touch counter intuitive but it works...
Public Sub DeleteChartSeries(chartSheet As Chart)
'Shorter but perhaps less clean way of writing the code compared to below
Do Until chartSheet.SeriesCollection.Count = 0
chartSheet.SeriesCollection(1).Delete
Loop
'With chartSheet
' Do Until .seriesCollection.Count = 0
' .seriesCollection(1).Delete
' Loop
'End With
End Sub
Just hit a workaround: First move the cursor somewhere outside the UsedRange, then create the Chart: Won't do auto-detection. Then move back.
In other words, the following code works for me (Excel 2007):
' Assume src As Range (proposed source data for the chart) in the ActiveSheet.
' put the cursor somewhere outside the UsedRange to avoid Excel's
' 'helpful' auto detection.
Dim ur As Range
Set ur = src.Worksheet.UsedRange
ur.Cells(1, ur.Columns.Count).Offset(0, 2).Select
Dim crt As Chart
Set crt = src.Worksheet.Shapes.AddChart().Chart
' ^ does NOT do auto-detection.
Probably can't prevent it being created, but you can delete it immediately after creating the chart, then create you own series as required.
In VBA:
Set Chrt = wb.Charts.Add()
Chrt.SeriesCollection(1).Delete